PHP Mailer多个电子邮件

时间:2016-06-08 11:53:08

标签: php email phpmailer

我的网站上有一张表格。当用户填写表单时,我希望通过表单中输入的数据向我发送电子邮件,并希望收到填写表单的人的电子邮件。

这是我正在使用的代码:

<?php
    function sendEmail($subject, $body) {
        require 'phpmailer/PHPMailerAutoload.php';
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->SMTPDebug = 0;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = "ssl"; // does tls works with port 25
        $mail->Host = 'smtp.zoho.com'; // is this the correct 
        $mail->Port = 465;
        $mail->Username = "noreply@domain.org";
        $mail->Password = "mypassword";
        $mail->SetFrom("noreply@domain.org");
        $mail->Subject = $subject;
        $mail->Body = $body;
        $mail->IsHTML(true);
        $mail->AddAddress('data@domain.org');

        if(!$mail->Send()) {
            $mail->ErrorInfo;
            echo "<script>alert('Error Occured sending the enquiry. Please try again')</script>";

        }
        else
        {
            echo "<script>window.location.href='http://domain.com/index.html'</script>";
        }
    }

    ?>

    <?php
    function sendEmail($subject, $body) {
        require 'phpmailer/PHPMailerAutoload.php';
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->SMTPDebug = 3;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = "ssl"; // does tls works with port 25
        $mail->Host = 'smtp.zoho.com'; // is this the correct 
        $mail->Port = 465;
        $mail->Username = "noreply@domain.org";
        $mail->Password = "mypassword";
        $mail->SetFrom("noreply@domain.org");
        $mail->Subject = $subject;
        $mail->Body = $body;
        $mail->IsHTML(true);
        $mail->AddAddress(''.$_POST['emailAddr'].''); // **

emailAddr是表单中电子邮件字段的名称,我希望向此电子邮件地址发送电子邮件。

        $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()) {
            $mail->ErrorInfo;
            echo "<script>alert('Error Occured sending the enquiry. Please try again')</script>";

        }
        else
        {
            echo "<script>window.location.href='http://domain.com/index.html'</script>";
        }
    }

    ?>

0 个答案:

没有答案