dongtan1845 2014-12-03 15:09
浏览 87
已采纳

如果发件人邮件无效,则Php Mail不起作用

In my website, I have a little contact form that uses PHP to send a mail to my personal e-mail address. In the form, I ask the user for his e-mail address. If the address exists, the script works perfectly, and will receive the message very quickly. But if the user enters a wrong mail address, I won't never receive it. Is it normal ? Here is a little piece of my script...

/* Prepare Email Subject */

$email_subject = '[CONTACT FORM]' . "\t" . $title;

/* Prepare Email Message */

$email_message .= "Nom: ".clean_string($name)."
";
$email_message .= "Email: ".clean_string($email)."
";
$email_message .= "Telephone: ".clean_string($tel)."
";
$email_message .= "Message: ".clean_string($msg)."
";

/* Prepare Email Header */

$headers = 'From: '.$email."
".

'Reply-To: '.$email."
" .

'X-Mailer: PHP/' . phpversion();

/* Send Email and redirect */

mail($email_to, $email_subject, $email_message, $headers);  
header ('location: /?status=success#contact');

I would like to thank you all for your answers. I am very sorry if the problem isn't clear enough, and I hope my english is understandable (I'm a Frenchy) !

For those who don't understand what is my problem :

In my script, I put the user's mail adress in the mail header. If the user gives me a valid e-mail, then I will receive the message, otherwise I won't.

Don't worry about the variables, this is just the last part of my script, but I verify all of them.

When I said "only if the address exists", I really wanted to mean that apparently, if the address is not registered, or if the domain does not exists, it does not work. Before sending the mail, I verify if the address is "valid" by applying a Regex test. And if I enter, for example : abcde@aeaefa.fr I won't receive the mail. That's why it is weird, the mail address format is good.

blue112, I am going to create a postmaster address, and use it to send these mails.

  • 写回答

2条回答 默认 最新

  • douwen3127 2014-12-03 15:13
    关注

    You shouldn't use the user's mail to send a mail.

    1. It's bad practice. You are kind of usurping it's identity
    2. If user uses, for instance, a gmail, and you're setting it to gmail, gmail won't trust you because he knows it never sends the email
    3. They are great chances the email falls in spam box

    The best way to go is a use a "valid" and trusted email to use in the "from" header field.

    Also, about your script, you can wrap the `mail``function in a if to know if everything went fine during the sending.

    if (mail($email_to, $email_subject, $email_message, $headers))
    {
        header ('location: /?status=success#contact');
    }
    else
    {
        echo "Sending mail failed";
    }
    

    This provides you no garentee that the mail succesfully arrived, however.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能