电子邮件不在实时服务器上运行,但通过本地主机Xampp工作

时间:2015-08-09 13:34:52

标签: php html xampp

嘿伙计们,我有这个奇怪的问题,从我的联系表格发送信息到我的电子邮件地址。我已经通过Xampp在本地主机上测试了我的代码,我收到的电子邮件非常好,但是当我将代码上传到服务器并提交时。成功消息显示应该但不接收电子邮件,即使在垃圾文件夹中也没有。

<?php
$name = $_POST['name1'];
$email = $_POST['email2'];
$message = $_POST['message3'];
$from = 'From: Testing';
$to = 'testing@hotmail.com';
$subject = 'Contact Form Testing';

$body = "From: $name\n Email: $email\n Message:\n $message";

if ($_POST['submit']){
    /*Do something when the submit has been pressed*/
    if (mail ($to, $subject, $body, $from)){
        $_SESSION['Success'] = '<div class="alert alert-success" role="alert">Your Message Has Been Sent!</div>';
        header('Location: index.php#fifthpage');
    } else{
        $_SESSION['Error'] = '<div class="alert alert-danger" role="alert">Something Went Wrong Please Try Again!</div>';
        header('Location: index.php#fifthpage');
    }
}

?>

1 个答案:

答案 0 :(得分:-1)

    $to = 'testing@hotmail.com';
    $from = $_POST['email2'];
    $subject = 'Contact Form Testing';
    $body = $_POST['message3']."\r\n";
    $headers = "From: $from\r\nReply-to: $from";
    $sent = mail($to, $subject, $body, $headers);

if($sent){
echo "The message was sent";
}
else{
    echo "Sending failed";
}