使用PHPmailer发送两封邮件时无法发送一封邮件

时间:2019-05-01 07:07:03

标签: php phpmailer

我正在尝试两个使用PHPMailer发送两封邮件,但我收到一封邮件,但是我没有收到第二封邮件(用户确认邮件)。有人可以帮我这个忙吗

include_once("mail/class.phpmailer.php");

$mail = new PHPMailer();           // Passing `true` enables exceptions

//Server settings
$mail->SMTPDebug = 1;                 // Enable verbose debug output
   //$mail->isSMTP();      //Set mailer to use SMTP(for live server remove or comment this line)
$mail->Host = 'mail.****.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '********';                 // SMTP username
$mail->Password = '********';                           // SMTP password
$mail->SMTPSecure = 'TSL';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                   // TCP port to connect to

//Recipients
$mail->From = $email_from;
$mail->FromName = $first_name;
$mail->addAddress('********@abc.com');     // Add a recipient


//Content
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'Here is the subject';
$txt='You got a mail from :<br>';

$mail->Body =$txt;
$mail->Send();


$mail->ClearAllRecipients();// Remove previous recipients
$mail->ClearAddresses();
$mail->From = "********@abc.com";
$mail->FromName = "Some Name";

$mail->AddAddress("********@abc.com");
$mail->IsHTML(true);

$thank_mesg = "Thank You For Sending Us Mail, We Will Reach You As Soon As Possible";
$mail->Subject = "Enquiry From xxxxxxx";

$mail->Body = $thank_mesg;
$mail->send();

1 个答案:

答案 0 :(得分:0)

以下是一些修正您的代码的建议:

首先,您可以使用phpMailer类的两个实例,例如:

require 'PHPMailerAutoload.php';

$mail = new PHPMailer(true);
$mail->isHTML();
$mail->IsSMTP(); 
$mail->setFrom('admin@mysite.com', 'admin site'); 
$mail->AddAddress($email);
$mail->Subject = $subject;
$mail->Body = $message1;
$mail->Send();

$mail2 = new PHPMailer(true);
$mail2->isHTML();
$mail2->IsSMTP(); 
$mail2->setFrom('admin@mysite.com', 'admin site'); 
$mail2->AddAddress($adminemail);
$mail2->Subject = $subject;
$mail2->Body = $message2;
$mail2->Send();

第二秒,某些提供程序对在特定时间内可以发送的消息数量施加了限制,因此请使用sleep()函数来检查消息是否有效。

$txt='You got a mail from :<br>';

$mail->Body =$txt;
$mail->Send();
sleep(10); // <<<--------------add this line - in second;

$mail->ClearAllRecipients();// Remove previous recipients
$mail->ClearAddresses();
$mail->From = "********@abc.com";
$mail->FromName = "Some Name";

$mail->AddAddress("********@abc.com");
$mail->IsHTML(true);

$thank_mesg = "Thank You For Sending Us Mail, We Will Reach You As Soon As Possible";
$mail->Subject = "Enquiry From xxxxxxx";

$mail->Body = $thank_mesg;
$mail->send();