Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用phpmailer发送感谢电子邮件_Php_Forms_Email_Smtp_Phpmailer - Fatal编程技术网

使用phpmailer发送感谢电子邮件

使用phpmailer发送感谢电子邮件,php,forms,email,smtp,phpmailer,Php,Forms,Email,Smtp,Phpmailer,我有一个phpmailer表格,发送电子邮件非常好,但我想每个表格发送2封电子邮件提交。第一封电子邮件应该是我自己的表单字段值。Thsi按预期工作。我正在toruble查找任何文件,允许我向提交表格的人发送第二封电子邮件,感谢联系我们,我们将很快联系。基本上,我想再发一封邮件给你,内容是“谢谢你”的value you$\u POST['email'] 表格代码(无任何感谢电子邮件): require'library/extensions/phpmailerautoad.php'; $mail=新

我有一个phpmailer表格,发送电子邮件非常好,但我想每个表格发送2封电子邮件提交。第一封电子邮件应该是我自己的表单字段值。Thsi按预期工作。我正在toruble查找任何文件,允许我向提交表格的人发送第二封电子邮件,感谢联系我们,我们将很快联系。基本上,我想再发一封邮件给你,内容是“谢谢你”的value you
$\u POST['email']

表格代码(无任何感谢电子邮件):

require'library/extensions/phpmailerautoad.php';
$mail=新的PHPMailer;
$strMessage=“”;
//仅当表单已提交时才执行操作
如果(isset($_POST['submit-contact-new'])){
//再次验证字段,因为不是每个人都有Javascript,包括机器人
如果(isset($\u POST['name'])和(&$\u POST['name'])!=“”&&
isset($\u POST['姓氏])&&$\u POST['姓氏]!==“”&&
isset($\u POST['email'])和&$\u POST['email']!=“”&&
isset($\u POST['phone'])和&$\u POST['phone'])!=“”&&
isset($\u POST['comment'])&&$\u POST['comment']!==“”){
//$mail->SMTPDebug=3;//启用详细调试输出
$mail->isSMTP();//设置邮件程序以使用SMTP
$mail->Host='mail.domain.com';//指定主SMTP服务器和备份SMTP服务器
$mail->SMTPAuth=true;//启用SMTP身份验证
$mail->Username=noreply@domain.com“;//SMTP用户名
$mail->Password='passwd';//SMTP密码
$mail->Fromnoreply@domain.com';
$mail->FromName='Domain';
$mail->addAddress('staffmember@domain.com“,“First-Last”);//添加收件人
$mail->isHTML(true);//将电子邮件格式设置为HTML
$mail->Subject='域表单查询';
$mail->Body=
域名网站查询
有关表格的资料如下:

名称:'.$\u POST['Name'.'

姓氏:'.$\u POST['姓氏].'

电子邮件:'.$\u POST['Email'.'

电话:“.$\u POST['Phone']”

查询:“.$\u POST['comment']

'; 如果(!$mail->send()){ //最后重定向 标头('Location:'.$\u SERVER['REQUEST\u URI'.'。?message='.$strMessage); }否则{ //最后重定向 标题('位置:http://domain.com/thank-you?location=“.$strLocation); } }否则{ //有点不对劲,所以想办法解决什么问题 如果(!isset($_POST['name'])|$_POST['name']==”)$strMessage.=“
  • 必须输入name
  • ”; 如果(!isset($|u POST[‘姓氏’])|$|u POST[‘姓氏’]=====”)$strMessage.=“
  • 必须输入姓氏
  • ”; 如果(isset($邮政['姓氏])&&isset($邮政['姓氏])&$邮政['姓名]===$邮政['姓氏])$strMessage.=“
  • 姓名和姓氏必须不同
  • ”; 如果(!isset($|u POST['phone'])|$| u POST['phone']==”)$strMessage.=“
  • 必须输入电话号码
  • ”; 如果(!isset($_POST['email'])|$_POST['email']==”)$strMessage.=“
  • 必须输入电子邮件”
  • ”; 如果(!isset($_POST['comment'])|$_POST['comment']==”)$strMessage.=“
  • 必须输入查询
  • ”; 如果($strMessage!==”)$strMessage=“
      ”$strMessage。”
    ”; //最后重定向 标头('Location:'.$\u SERVER['REQUEST\u URI'.'。?message='.$strMessage); 退出(); } } ?>
    要解决这个问题,我只需在这个表单操作中放置另一个实例,并运行phpmailer两次。这使我能够使用相同的帖子内容设置单独的正文内容和收件人

    <?php
        require 'library/extensions/PHPMailerAutoload.php';
    
        $mail = new PHPMailer;
        $strMessage = "";
        //Only action if the form has been submitted
        if(isset($_POST['submit-contact-new'])) {
    
        //$mail->SMTPDebug = 3;                               // Enable verbose debug output
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'mail.domain.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'noreply@domain.com';                 // SMTP username
        $mail->Password = 'passwd';                           // SMTP password
        $mail->From = 'noreply@domain.com';
        $mail->FromName = 'Domain';
        $mail->addAddress('staff@domain.com', 'Staff Name');     // Add a recipient
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Domain Form Enquiry';
        $mail->Body    = '
        <html>
                        <body>
                            <h1>Domain Website Enquiry</h1>
                            <p>Information on form was:</p>
                            <p><strong>Name</strong>: '.$_POST['name'].'</p>
                            <p><strong>Surname</strong>: '.$_POST['surname'].'</p>
                            <p><strong>Email</strong>: '.$_POST['email'].'</p>
                            <p><strong>Phone</strong>: '.$_POST['phone'].'</p>
                            <p><strong>Enquiry</strong>: '.$_POST['comment'].'</p>
                        </body>
                    </html>
                    ';
        if(!$mail->send()) {
           //Finally redirect
                echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
          //Finally redirect
                header('Location: http://domain.com/thank-you?location='.$strLocation) ;
        }
        }
        $mail = new PHPMailer;
        $strMessage = "";
        //Only action if the form has been submitted
        if(isset($_POST['submit-contact-new'])) {
    
        //$mail->SMTPDebug = 3;                               // Enable verbose debug output
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'mail.domain.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'noreply@rdomain.com';                 // SMTP username
        $mail->Password = 'password';                           // SMTP password
        $mail->From = 'noreply@domain.com';
        $mail->FromName = 'Domain';
        $mail->addAddress(''.$_POST['email'].'');     // Add a recipient
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Thank you for contacting Domain';
        $mail->Body    = 'Thanks for getting in touch. Your message has been received and will be processed as soon as possible.';
        if(!$mail->send()) {
           //Finally redirect
                echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
          //Finally redirect
                header('Location: http://domain.com/thank-you?location='.$strLocation) ;
        }
        }
        ?>
    
    
    
    添加此$mail->AddAddress($\u POST['email']);在$mail->addAddress('staffmember@domain.com","最后一次",@诺曼:这将向双方发送相同的正文内容,而我希望向双方发送不同的正文内容。谢谢,然后将代码包装到函数中,并传递两个参数:1用于电子邮件,2用于邮件正文。只需在这里调用函数,使用参数传递不同的电子邮件和消息正文。然后享受:)你能展示一下它是如何工作的吗?我对php没那么在行。很抱歉谢谢您的帮助。您可以这样做,但是调用clearAllRecipients、更改您想要的任何其他位并再次调用send更有效,所有这些都使用相同的phpMail实例。
    <?php
        require 'library/extensions/PHPMailerAutoload.php';
    
        $mail = new PHPMailer;
        $strMessage = "";
        //Only action if the form has been submitted
        if(isset($_POST['submit-contact-new'])) {
    
        //$mail->SMTPDebug = 3;                               // Enable verbose debug output
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'mail.domain.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'noreply@domain.com';                 // SMTP username
        $mail->Password = 'passwd';                           // SMTP password
        $mail->From = 'noreply@domain.com';
        $mail->FromName = 'Domain';
        $mail->addAddress('staff@domain.com', 'Staff Name');     // Add a recipient
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Domain Form Enquiry';
        $mail->Body    = '
        <html>
                        <body>
                            <h1>Domain Website Enquiry</h1>
                            <p>Information on form was:</p>
                            <p><strong>Name</strong>: '.$_POST['name'].'</p>
                            <p><strong>Surname</strong>: '.$_POST['surname'].'</p>
                            <p><strong>Email</strong>: '.$_POST['email'].'</p>
                            <p><strong>Phone</strong>: '.$_POST['phone'].'</p>
                            <p><strong>Enquiry</strong>: '.$_POST['comment'].'</p>
                        </body>
                    </html>
                    ';
        if(!$mail->send()) {
           //Finally redirect
                echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
          //Finally redirect
                header('Location: http://domain.com/thank-you?location='.$strLocation) ;
        }
        }
        $mail = new PHPMailer;
        $strMessage = "";
        //Only action if the form has been submitted
        if(isset($_POST['submit-contact-new'])) {
    
        //$mail->SMTPDebug = 3;                               // Enable verbose debug output
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'mail.domain.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'noreply@rdomain.com';                 // SMTP username
        $mail->Password = 'password';                           // SMTP password
        $mail->From = 'noreply@domain.com';
        $mail->FromName = 'Domain';
        $mail->addAddress(''.$_POST['email'].'');     // Add a recipient
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Thank you for contacting Domain';
        $mail->Body    = 'Thanks for getting in touch. Your message has been received and will be processed as soon as possible.';
        if(!$mail->send()) {
           //Finally redirect
                echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
          //Finally redirect
                header('Location: http://domain.com/thank-you?location='.$strLocation) ;
        }
        }
        ?>