0

我在stackoverflow.com上找到了很多答案,但没有帮助我,所以我不得不问

问题:Phpmailer 发送邮件但空白邮件!没有身体没有执着!

//Create a new PHPMailer instance
$mail = new PHPMailer();

$mail->CharSet = 'UTF-8';

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = 465;  // set the SMTP port for the GMAIL server; 465 for ssl and 587 for tls
$mail->Username   = "services@domain.xxx"; // Gmail account username
$mail->Password   = "pwd";        // Gmail account password


//$mail->Mailer = 'smtp';
//Set who the message is to be sent from
$mail->SetFrom(service_mail_d, 'XXXX Services');
//Set an alternative reply-to address
$mail->AddReplyTo(service_mail_d, 'XXXX Services');
//Set who the message is to be sent to
$mail->AddAddress("testcenter@xxxx.xxxxx", "Client1");
//Set the subject line
$mail->Subject = "service_order_subject" ;
//Read an HTML message body from an external file, convert referenced images to embedded,convert HTML into a basic plain-text alternative body
$mail->MsgHTML("<h1>Simple TEST</h1>");
$mail->AddStringAttachment($generator_file_content,$generatorId ."html",'UTF-8','text/html');
 //Send the message, check for errors
$mailSend=$mail->Send();

更新:

如果没有添加StringAttachment,可以看到它的发送邮件和MsgBody!

4

2 回答 2

1

将代码更改为:

$mail->AddStringAttachment($generator_file_content,$generatorId ."html",'UTF-8','text/html');
 //Send the message, check for errors
$mailSend=$mail->Send();

至:

$mail->AddStringAttachment($generator_file_content,$generatorId ."html");
// 'UTF-8','text/html');

if($mail->Send())
    echo "Mail sent";
else
    echo "Mail NOT sent";
于 2013-08-28T06:23:32.023 回答
0

问题是您对“编码”参数的误解。该参数不表示文件的编码,而是文件的目标 MIME 编码。从文档中,您可以使用以下任何值:

  • base64
  • 7位
  • 8位
  • 二进制
  • 引用可打印
于 2015-01-06T19:50:38.310 回答