php邮件程序无法向除我之外的任何人发送电子邮件

时间:2012-08-17 06:56:01

标签: php phpmailer

我正在使用php邮件程序类向我的客户发送电子邮件。但它失败了,错误:

Language string failed to load: recipients_failed example@gmail.com

如果我将$ email_to和$ email_from的值更改为同一个电子邮件地址,则电子邮件会成功发送

这是我发送电子邮件的代码

$email_to = "example@gmail.com";
$email_subject = "bla bla";
$email_from = 'info@domain.com.vn';
$email_message = "hello there";

$mail = new PHPMailer();
$mail->CharSet="UTF-8";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.domain.com.vn"; // SMTP server
$mail->From = $email_from;
$mail->AddAddress($email_to);
$mail->AddReplyTo($email_from);     
$mail->Subject = $email_subject;
$mail->WordWrap = 100; 
$mail->Body = $htmlBody;
$mail->isHTML(true);
$mail->AltBody = $email_message;
if(!$mail->Send()){
   echo $mail->ErrorInfo; 
}

因此,除非我将$ email_to更改为info@domain.com.vn

,否则它将始终报告错误

谢谢,

2 个答案:

答案 0 :(得分:1)

注意:请将SMTP服务器设置更改为您自己的服务器。

$your_email = "info@example.com";
$your_smtp = "mail.example.com";
$your_smtp_user = "info@example.com";
$your_smtp_pass = "example_password";
$your_website = "http://example.com";

//get contact form details
$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$comments = $_POST['comments'];

$response="Name: $name\nContents:\n$comments\n";

$mail = new PHPmailer();
$mail = $mail->SetLanguage("en", "phpmailer/language");
$mail->From = $your_email;
$mail->FromName = $your_website;
$mail->Host = $your_smtp;
$mail->Mailer   = "smtp";
$mail->Password = $your_smtp_pass;
$mail->Username = $your_smtp_user;
$mail->Subject = "$your_website feedback";
$mail->SMTPAuth  =  "true";
$mail->Body = $response;
$mail->AddAddress($your_email,"$your_website admin");
$mail->AddReplyTo($email,$name);

echo "<p>Thanks for your feedback, <em>$name</em>! We will contact you soon!</p>";
if (!$mail->Send()) {
echo "<p>There was an error in sending mail, please try again at a later time</p>";
}

$mail->ClearAddresses();
$mail->ClearAttachments();

答案 1 :(得分:0)

我认为您需要设置语言文件的语言和路径,如下所示:

$mail->SetLanguage ("de", "./phpmailer/");

如果这不能解决。确保语言文件确实存在于该文件夹中(如果可能,请使用相对路径)并且在Linux下:文件应该与php脚本具有相同的所有者并且正确(读取文件权限)。

相关问题