1

我正在使用 php mailer 类向我的客户发送电子邮件。但它失败并出现错误:

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

谢谢,

4

2 回答 2

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();
于 2012-08-17T07:09:39.877 回答
0

我认为您需要像这样设置语言文件的语言和路径:

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

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

于 2012-08-17T07:08:02.270 回答