PHP SMTP邮件联系表(PHP SMTP Mail Contact form)

2019-11-01 03:50发布

我一直在使用使用梨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>");
 }
 ?>

谢谢,

Answer 1:

你可以在头阵列使用CC

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

或者前夕尤为明显

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


Answer 2:

如果你希望他们接受你得到了相同的电子邮件伊万的解决方案是好的。

但最好是简单地给他一个不同的电子邮件。

您生成两个。 一旦你和一个他。

如果您想拥有共同的部分使用单独的变量是,只是追加或预先准备的消息。



文章来源: PHP SMTP Mail Contact form
标签: php smtp