简体   繁体   English

使用PHP Mailer的Ajax表单提交错误

[英]Ajax form submission error using PHP Mailer

I implemented this http://www.websitecodetutorials.com/code/jquery-plugins/jquery-ajaxsubmit.php tutorial on my form, and the form works successfully and displays the thank you div on submission. 我在表单上实现了此http://www.websitecodetutorials.com/code/jquery-plugins/jquery-ajaxsubmit.php教程,该表单成功运行并在提交时显示了感谢div。 But the problem is I don't receieve any email, seems like PHP mailer is not working. 但是问题是我没有收到任何电子邮件,似乎PHP邮件程序无法正常工作。

Please see the code below 请看下面的代码

    <?php
// Insert your email/web addresses and correct paths
$mailto = 'adil@adilsaleem.co.uk' ;
$from = "web@city.com" ;
$formurl = "http://astonstorlin.co.uk/citycoaches3/formmail.php" ;
$errorurl = "http://astonstorlin.co.uk/citycoaches3/error.php" ;
$thankyouurl = "http://astonstorlin.co.uk/citycoaches3/thankyou.php" ;

// Place Your Form info here...
$pickuppoint = ($_POST['pickuppoint']);
$destination = ($_POST['destination']);

// Check If Empty

// Add more Validation/Cleaning here...

// Place your Corresponding info here...
$message =

    "Pick Point: $pickuppoint\n\n" .
    "Destination: $destination\n\n" . 
    "noppl: $noppl\n\n" 
;

// Leave Alone
mail($mailto, $from, $message,
    "From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep );
header( "Location: $thankyouurl" );
exit ;

?>

I think your headers are not working. 我认为您的标题不起作用。 $headersep is not defined and moreover please follow : $ headersep未定义,此外,请遵循:

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

@mail($to, $subject, $message, $headers);

Example copied from http://php.net/manual/en/function.mail.php you can refer for more reading this link. http://php.net/manual/en/function.mail.php复制的示例,您可以参考以获取更多阅读此链接的信息。

If you are on a shared hosting for example, sometimes they require you to use a fifth parameter like additional_parameters. 例如,如果您在共享主机上,则有时它们要求您使用第五个参数,例如Additional_parameters。

mail('nobody@example.com', 'the subject', 'the message', null,'-fwebmaster@example.com');

Check example 3 here: http://php.net/manual/en/function.mail.php 在此处检查示例3: http//php.net/manual/en/function.mail.php

Thank you very much for all your help people, much appreciated. 非常感谢您提供的所有帮助,非常感谢。

I got the script working by deleting 我通过删除使脚本工作

"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep );

And the script started working. 脚本开始工作。 I have tried using other HTML php mailer but them don't seem to work with this tutorial example for some reason. 我曾尝试使用其他HTML php邮件程序,但由于某些原因它们似乎无法与本教程示例一起使用。 http://www.websitecodetutorials.com/code/jquery-plugins/jquery-ajaxsubmit.php http://www.websitecodetutorials.com/code/jquery-plugins/jquery-ajaxsubmit.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM