dtng25909 2019-02-02 14:47
浏览 85
已采纳

Php电子邮件表单不从Web电子邮件表单发送电子邮件

I am trying to troubleshoot this form. It is not sending reservation requests from the form on the website. Despite showing a message that the form was sent.

I tried editing email and the headers.

<?
//print_r($_POST);

$to = “email@emaildomain.com, {$posting['email']}";
function msg($text){
echo "
    <script type='text/javascript'>
    alert('".$text."');
    top.location.href = 'http://www.aribbq.com';
    </script>
";
exit;
}

function error($text){
echo "
    <script type='text/javascript'>
    alert('".$text."');
    history.go(-1);
    </script>
";
exit;
}

if (!$_POST[date]) {error('Please, insert Date.');}
if (!$_POST[time]) {error('Please, insert Time.');}
if (!$_POST[party]) {error('Please, insert Party.');}
if (!$_POST[reservation_name]) {error('Please, insert Name.');}
if (!$_POST[reservation_email]) {error('Please, insert Email.');}
if (!$_POST[reservation_phone]) {error('Please, insert Phone.');}  
if(isset($_POST['submit'])){
 // then send the form to your email

//$from = ('Reservation from AriBBQ.com'); // sender
$mailheaders = "From: contact@aribbq.com" . "
"; // . "CC: 
design@youremail.com"
$mailheaders .= 'Reply-To: ' . $posting['Email'] . "
";
$subject = "AriBBQ.com Online Reservation";
$body = "
 Contact Name: ".$_POST[reservation_name]." 

"; 
//
$body .= " Email: ".$_POST[reservation_email]." 

"; //
$body .= " =================================================== 

"; //
$body .= "  Book a table 


            Date: ".$_POST[date]." 


            Time: ".$_POST[time]." 


            Party: ".$_POST[party]." 


            Contact Details 


            Name: ".$_POST[reservation_name]." 


            Email: ".$_POST[reservation_email]." 


            Phone: ".$_POST[reservation_phone]." 


            Message: ".$_POST[reservation_message]." 

"; //
$body .= " =================================================== 

"; //


$result = mail($to , $from , $subject , $body , $mailheaders); 
if($result) {msg('Thank you, your reservation has been sent. We 
will send you a confirmation text or call in person.');} // 
else{error('Sending mail is failed. Please try again');} //

} else {
error('No submitted. Please try again');
}

?>

You see the form online at http://aribbq.com/. Click on reservations. Once the email is received, we want to be able to reply to the sender's email address.

  • 写回答

2条回答 默认 最新

  • douye6812 2019-02-02 15:45
    关注

    Alright, essentially, you need to turn on error reporting because your script threw about 20 errors at me which you would see with error reporting on. As my comment above said, add error_reporting(E_ALL); to the top of your script while you debug.

    The issues I came across are as follows:

    Parse error: syntax error, unexpected '@' in /mail.php on line 4 caused by an incorrect double quote character, not " but . Subtle, but problematic.

    Next up, Multiple or malformed newlines found in additional_header in /mail.php because as of PHP 5.5.2, a bug was fixed to prevent mail header injection, so all of your within the $mailheaders should be removed, I recommend appending PHP_EOL to the end of each line instead.

    You have your $from variable included in the mail() call, this presents 2 issues. One, the mail() function does not have a from parameter, you include it within the headers. Two - your variable is actually commented out.

    As I mentioned in the comment above, again, your email address variable to send to is typed as $posting['email']', and $posting['Email'] within $mailheaders. The problem here is $posting doesn't exist. Secondly, your form, which you should include the HTML for in future questions for self-contained examples for people to more easily help you (see https://stackoverflow.com/help/how-to-ask), doesn't post email at all, it posts reservation_email.

    Finally, the majority of your $_POST references do not include quotes so PHP doesn't know what to do with the words in between the square brackets. $_POST[date] should be $_POST['date'], for example.

    I've made all the above changes and managed to successfully email myself with the script and email form provided, the only thing that I didn't look at was your msg() which didn't show me a success message. I did, however, put an echo statement before this function call which printed out fine.

    I hope this helps you get your script up and running, good luck and remember, error_reporting(); is your friend!

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀