【问题标题】:Sending Email from web form using php使用 php 从 web 表单发送电子邮件
【发布时间】:2015-03-14 04:34:40
【问题描述】:

我编写了一个 php 脚本,以便在使用单击按钮时从 Web 表单发送电子邮件。该邮件正在运行,但它在收件箱中显示此警告消息:“此邮件可能不是从 example@example.com 发送的”。这是我的php代码:

<?php
if(isset($_POST['send'])){

    $to = 'indra.web@satenterprise.com';
    $subject = 'Booking';

    $message = 'Name:' . $_POST['name'] . "\r\n\r\n";
    $message .= 'Email:' . $_POST['email'] . "\r\n\r\n";
    $message .= 'Phone:' . $_POST['message'] . "\r\n\r\n";

    $headers = "From:" .$_POST['email'] . "\r\n\r\n";
    $headers .= 'Content-Type: text/plain; charset=utf-8';

    $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
    if($email){
        $headers .= "\r\nReply-To: $email";
    }

    $success = mail($to, $subject, $message, $headers);

    if(isset($success) && $success){ ?>
         <h4 style="font-family: Arial; color: #777777;">Thank You, your mail has been sent. We will be in touch with you very soon.</h4>
    <?php }else{
        echo "Sorry, there was a problem sending your message";
    }
}
?>

有什么办法可以消除这个令人不安的信息吗? 谢谢

【问题讨论】:

  • 如果您的电子邮件已送达发件人,那么为什么不使用errror_reporting(0); 呢?
  • @SulthanAllaudeen error_reporting() 是一个 PHP 函数。警告消息出现在不涉及 PHP 的收件人收件箱中的消息中。
  • 对不起,我认为一旦触发电子邮件就会引发错误。谢谢:)
  • @Indra :您在$_POST['email'] 中的发件人地址是什么,因为有些服务器也处理这个问题。尝试使用真实的电子邮件地址
  • @SulthanAllaudeen 我在 $_POST['email] 中使用了真实的电子邮件地址。

标签: php html email


【解决方案1】:

下面的代码可以试试这个..

<?php
$contact_name=$_POST['contact_name'];
$contact_email=$_POST['contact_email'];
$contact_phone=$_POST['contact_phone'];
$contact_message=$_POST['contact_message'];
$to_email = 'xxx@domain.com'; //you can give email id to whom you need to send
$html = 'your custom body of the mail';
$subject = 'you subject' . $contact_message;
$message = $html;
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ABC' . "\r\n"; //DONT GIVE SPACE IN "ABC"  //you can replace your value but no space.. if u give space you can get email in spam only..
$response = mail($to_email,$subject,$message,$headers);
if($response)
{
    echo "Mail sent";
}
else
{
    echo "Not sent.. Try later";
}
?>

【讨论】:

    猜你喜欢
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 2016-01-12
    相关资源
    最近更新 更多