donglefu6195 2017-04-08 19:00
浏览 66

使用PHP通过SendMail发送邮件

I am working on a basic Contact Us form that will send me a quick message from the user. The code is below. When I test it, no message is sent. However, I can send messages from command line using the sendmail.

Could someone tell me what I need to do to configure this setup? I have tried looking at PHP error logs but there was nothing there. Can I find sendmail logs somewhere?

Also, if this helps, the site is running on an AWS EC2 instance, with DNS configured through Route53 and is being served as a virtual host by the Apache.

<?php
if (isset($_POST) && sizeof($_POST) > 0) {

    //$to = $_POST['to']['val']; // <=== Set static email here.
    $to = "xxxx@test.com";
    error_log("Entered the formdata.php script!", 0);
    error_log("To value:" . $to, 0);

    if (isset($_POST['formtype'])) {
        unset($_POST['formtype']);
    }
    if (isset($_POST['to'])) {
        unset($_POST['to']);
    }
    error_log("To value:" . $to, 0);

    $email_address = $_POST['email']['val'];
    error_log("Email address:" . $email_address, 0);
    $email_subject = "Form submitted by: ".$_POST['name']['val'];
    $email_body    = "You have received a new message. <br/>".
                     "Here are the details: <br/><br/>";
                     foreach ($_POST as $key => $value) {
                        $email_body .= "<strong>" . $value['label'] . ": </strong> " . $value['val'] . "<br/><br/>";
                     }

    $headers = "From:<$email_address>
";
    $headers.= "Content-Type:text/html; charset=UTF-8";
    if($email_address != "") {
        mail($to,$email_subject,$email_body,$headers);
        return true;
    }
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据