[英]Can't send an email with PHP
I am trying to send an confirmation email after user makes an account. 我尝试在用户注册帐户后发送确认电子邮件。 The email doesn't send anything.
电子邮件没有发送任何东西。 I did test it and the email is not even going to the spam or inbox folder.
我确实对其进行了测试,并且电子邮件甚至都没有进入垃圾邮件或收件箱文件夹。 Am I missing something?
我想念什么吗? Thank you for your help.
谢谢您的帮助。
$status = "";
if (isset($_POST["sign_up"])) {
$first_name = (isset($_POST['first_name']) ? $_POST['first_name'] : null);
$last_name = (isset($_POST['last_name']) ? $_POST['last_name'] : null);
$username = (isset($_POST['username']) ? $_POST['username'] : null);
$password = (isset($_POST['password']) ? $_POST['password'] : null);
$email = (isset($_POST['email']) ? $_POST['email'] : null);
$phone = (isset($_POST['phone']) ? $_POST['phone'] : null);
if ($first_name == "" || $last_name == "" || $username == "" || $password == "" || $email == "" || $phone == "") {
$status = '<p style="color:#FF0000;">Please fill out all the field';
} else if (strlen($password) < 6) {
$status = '<p style="color:#FF0000;">Password must more than 6 characters';
} else{
$sql = "INSERT INTO members(
first_name,
last_name,
username,
password,
email,
phone
) VALUES (
'$first_name',
'$last_name',
'$username',
'$password',
'$email',
'$phone'
)";
$res = mysqli_query($mysqli,$sql) or die(mysqli_error());
if ($res) {
$to = $email;
$subject = "Confirmation from Yu Fong to $username";
$from = "abc@yahoo.com";
$message = "Please click the link below to verify and activate your account. \r\n";
$message .= "Testing";
$header = "From: " .$from. "\r\n";
$header .="Reply-To: ".$from. "\r\n";
$header .= "CC: abc@yahoo.com\r\n";
$header .= "Return-Path: ".$from. "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header .= "X-Priority: 3\r\n";
$header .= "X-Mailer: PHP". phpversion() ."\r\n";
$sentmail = mail($to, $subject, $message, $header);
if ($sentmail == true) {
echo $status = '<p style="color:#FF0000;">Congratulations! Your account has been created. An confirmation email has been sent!';
} else {
echo "Eror!";
}
}
}
}
I just tested your email form,it works perfectly,i got the email. 我刚刚测试了您的电子邮件表格,它运行正常,我收到了电子邮件。
$to = "Myemail@derp.derp";
$subject = "Confirmation from Yu Fong to $username";
$from = "derpington";
$message = "Please click the link below to verify and activate your account. \r\n";
$message .= "Testing";
$header = "From: " .$from. "\r\n";
$header .="Reply-To: ".$from. "\r\n";
$header .= "CC: abc@yahoo.com\r\n";
$header .= "Return-Path: ".$from. "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header .= "X-Priority: 3\r\n";
$header .= "X-Mailer: PHP". phpversion() ."\r\n";
$sentmail = mail($to, $subject, $message, $header);
if ($sentmail == true) {
echo $status = '<p style="color:#FF0000;">Congratulations! Your account has been created. An confirmation email has been sent!';
} else {
echo "Eror!";
}
This is just your form,and it works so i am assuming the issue is coming from another place,try changing 这只是您的表格,并且有效,所以我假设问题出在另一个地方,请尝试更改
if ($res) {
to 至
if (1+1 == 2) {
just to check if your If statement actually prints true,and go from there. 只是要检查您的If语句是否实际打印为true,然后从那里开始。
Try changing 尝试改变
if ($sentmail == true) { ...
to 至
if ($sentmail) { ...
Or to shorten it a bit try 或缩短一点尝试
if(@mail($to, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.