2019-02-02 14:47
浏览 85


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.


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

function error($text){
echo "
    <script type='text/javascript'>

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.');}  
 // then send the form to your email

//$from = ('Reservation from AriBBQ.com'); // sender
$mailheaders = "From: contact@aribbq.com" . "
"; // . "CC: 
$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!

    点赞 评论
  • douzhenqun1271 2019-02-02 14:59

    mail() function is disbled on most servers, try to send mail from smtp PhpMailer is a good solution for that.

    点赞 评论

相关推荐 更多相似问题