我想在用户提交表单后通过电子邮件发送表单数据。以下是我的PHP脚本。此脚本正在执行但邮件永远不会到来。有人可以帮助我,因为我是php的新手。
<?php
if(isset($_POST['submit'])){
$to = "saxena@designmaniac.in";
$From = $_POST['email'];
$subject = "Student Admission Form";
$subject2 = "Copy of your form submission";
$first_name = $_POST["name_f"];
$email = $_POST["email"];
$mobile_number = $_POST["mobile_number"];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$headers);
mail($from,$subject2,$headers2);
}
?>
提前致谢 Saxena先生
答案 0 :(得分:1)
你有一个小而重要且有效的错误:
$From = $_POST['email'];
使用大写
定义$ From$ From!= $ from
php区分大小写
答案 1 :(得分:0)
这些是可能性:
试试这段代码:
$to = "somebody@example.com";
$subject = "My subject";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";
$txt = "Hello world!";
mail($to,$subject,$txt,$headers);
由于
答案 2 :(得分:0)
你必须要尝试这个。有时我们必须在Header中发送 X-Mailer 。它可能会解决您的问题。
<?php
if(isset($_POST['submit'])){
$to = 'saxena@designmaniac.in';
$from = $_POST['email'];
$header[] = 'From: '.$from;
$header[] = 'Content-type:text/html; charset=UTF-8';
$header[] = 'X-Mailer: PHP/'.phpversion();
$subject = 'Student Admission Form';
$body = '<h1>Prodest, inquit, mihi eo esse animo.</h1><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed residamus, inquit, si placet. <b>Non est igitur voluptas bonum.</b> <mark>Duo Reges: constructio interrete.</mark> Sed residamus, inquit, si placet. A mene tu?';
$headers = implode($header, "\r\n");
$status = mail($to, $subject, $body, $headers);
var_dump($status);
}
答案 3 :(得分:0)
以上代码在本地服务器上正常工作,而不是在live ..如果电子邮件发送正常工作,你可以使用sendgrid方法