我使用PHPMailer收到两条消息 [英] I receive two messages using PHPMailer

查看:95
本文介绍了我使用PHPMailer收到两条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么会有两条消息出现在我的邮件中. 发送功能启动一次,关于成功发送的消息显示一次.

I do not understand why two messages come to my mail. The send function is launched once and the message about the successful sending displays once.

<?php

require('class.phpmailer.php');

    $email = new PHPMailer();
    $email->CharSet = 'UTF-8';
    $email->From      = $_POST['mailmy'];
    $email->FromName  = '«Тэкс»';
    $email->Subject   = 'Ваша новая кухня почти готова.';
    $email->Body      = $_POST['mailText'];
    $email->AddAddress( $_POST['mailMeil']);

    $email->Send(); 
    echo 'Message has been sent';
    if (!$email->send()) {
    echo "Mailer Error: " . $email->ErrorInfo;
} else {
    echo "Message sent!";
}

?>

推荐答案

您两次调用send()方法:

$email->Send(); // first time
echo 'Message has been sent';
if (!$email->send()) { // second time

代码完全按照您的指示执行:发送两次.

The code is doing exactly what you told it to do: send twice.

您应该做的是第一次存储结果并进行测试:

What you should do is store the result the first time and test that:

$sent = $email->Send();
echo 'Message has been sent';
if (!$sent) {

顺便说一句:您的echo声明没有任何意义.如果您还不知道该消息,则不要告诉用户.

As an aside: your echo statement there doesn’t make sense. You shouldn’t tell the user the message has been sent if you don’t know that yet.

这篇关于我使用PHPMailer收到两条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆