【问题标题】:PHP SMTP Mail Contact formPHP SMTP 邮件联系表
【发布时间】:2012-10-19 23:15:34
【问题描述】:

我有一个使用 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>");
 }
 ?>

谢谢,

【问题讨论】:

  • 您想要确认电子邮件还是电子邮件副本(按照 Ivan 的建议)? :)

标签: php smtp


【解决方案1】:

你可以在 headers 数组中使用 CC

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

或者更好

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

【讨论】:

  • 是的,我考虑过密件抄送,但我希望它与我收到的信息有点不同,但现在我想起来,这两种方式都没有关系..
【解决方案2】:

如果您希望他们收到与您收到的相同的电子邮件,Ivan 的解决方案是很好的。

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

你生成两个。一份给你,一份给他。

如果您想使用公共部分,请为此使用单独的变量,然后将其附加或预先添加到消息中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-27
    • 2017-02-03
    • 2013-02-11
    • 2014-01-23
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    相关资源
    最近更新 更多