简体   繁体   English

phpmailer成功,但未发送电子邮件

[英]phpmailer success but no email sent

PHPMailer says successful but email is not being sent. PHPMailer说成功,但是未发送电子邮件。 Email trace doesn't show any errrors. 电子邮件跟踪不显示任何错误。 From sending or receiving email. 通过发送或接收电子邮件。 Is there something that I'm missing? 有什么我想念的吗?

Below is my mailer.php file: 以下是我的mailer.php文件:

    require 'class.phpmailer.php';
require 'class.smtp.php';

$mail = new PHPMailer;


$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'localhost';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'diane@example.com';                            // SMTP username: FROM EMAIL
$mail->Password = 'pw';                           // SMTP password: FROM PW


$mail->From = 'diane@example.com'; //FROM EMAIL
$mail->addAddress('terry@example.com');               // Add a recipient, Name is optional


$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Contact Form';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';

I'm not sure why you're using this method to send email in PHP. 我不确定为什么要使用此方法在PHP中发送电子邮件。 Here's a better way to accomplish this: 这是实现此目的的更好方法:

$to = 'test@test.com';
$subject = 'Lorem Ipsum';
$from = 'me@me.com';
$message = 'Congrats! You won! Message body here.';
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM