我在 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!
答案 0 :(得分: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";
答案 1 :(得分:0)
问题是你对“编码”参数的误解。此参数不指示文件的编码,而是指示文件的目标MIME编码。从documentation开始,您可以使用以下任何值: