PHP SMTP邮件联系表单

时间:2012-10-19 23:15:35

标签: php smtp

我有一个使用Pear的SMTP身份验证的联系表单。我也想向填写表格的人发​​送确认电子邮件。

我必须添加到我的php才能实现这一目标

<?php
        error_reporting(E_ALL);
        ini_set('display_errors', True);

        set_include_path('******');

        require_once "Mail.php";

// Set the email variables from the form here:

    $name = $_POST['name']; // Pass the Name value to the $Name variable
    $number = $_POST['number'];
    $email = $_POST['email']; // Pass the Email value to the $Email variable
    $enquiry = $_POST['enquiry'];
    $comment = $_POST['message']; // Pass the Comment value to the $Comment variable

 $from = $email;
 $to = "Enquiries <enquiries@brisbanediveacademy.com.au>";
 $subject = "Enquiry ( $enquiry)";

        $body = "You have received a Web Enquiry. \n
            Name: $name\n
            Contact: $number \n
            Email: $email\n
            Enquiry Type: $enquiry \n
            Comments: $comment";

 $host = "******.com.au";
 $username = "*****.com.au";
 $password = "******";

 $headers = array('From' => $from,
                  'To' => $to,
                  'Subject' => $subject);
 $smtp = Mail::factory('smtp',
                       array('host' => $host,
                            'auth' => true,
                            'username' => $username,
                            'password' => $password));

 $mail = $smtp->send($to, $headers, $body);

 if (PEAR::isError($mail)) {
     echo("<p>" . $mail->getMessage() . "</p>");
 } else {
     echo("<p>Message successfully sent! We will be in contact with you shortly!</p>");
 }
 ?>

谢谢,

2 个答案:

答案 0 :(得分:2)

您可以在标题数组中使用CC

 'Cc' => 'Sendername <$from>',

或前夕

'Bcc' => 'Sendername <$from>',

答案 1 :(得分:0)

Ivan的解决方案很好,如果你希望他们收到你收到的同一封邮件。

但最好只是给他发一封电子邮件。

你生成两个。一次为你而一次为他。

如果你想让公共部分使用一个单独的变量,只需附加或添加到消息中。