我没有收到邮件

$to = 'someone.com';

$firstname = $_POST["fname"];

$lastname = $_POST["fname"];

$subject= $_POST["subject"];

$email= $_POST["email"];

$text= $_POST["message"];




$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= "From: " . $email . "\r\n"; // Sender's E-mail

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

这是我的 php 页面的代码。你能让我知道我的代码有什么问题吗?感谢您的帮助


if (mail($to,$subject,$text,$headers))

{

  echo "Check Email please";

}

 else

{

    echo 'failed';

}


慕盖茨4494581
浏览 76回答 1
1回答

胡说叔叔

请确保您在顶部添加 Phpmailer 类。这是一个正常工作的邮件程序文件,将您的凭据放在这里并发送电子邮件。<!DOCTYPE html><html><head>&nbsp; &nbsp; <title>Php Mailer</title>&nbsp; &nbsp; <link rel="stylesheet" type="text/css" href="bootstrap.min.css"></head><body>&nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp;&nbsp; &nbsp; // require 'PHPMailerAutoload.php';&nbsp; &nbsp; &nbsp; &nbsp; require("PHPMailer-master/src/PHPMailer.php");&nbsp; &nbsp; &nbsp; &nbsp; require("PHPMailer-master/src/SMTP.php");&nbsp; &nbsp; &nbsp; &nbsp; require("PHPMailer-master/src/Exception.php");&nbsp; &nbsp; &nbsp; &nbsp; $mail = new PHPMailer\PHPMailer\PHPMailer();&nbsp; &nbsp; &nbsp; &nbsp; $SendMailTo = "jonipk28@gmail.com";&nbsp; &nbsp; &nbsp; &nbsp; $mail->SMTPDebug = 0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; $mail->isSMTP();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set mailer to use SMTP&nbsp; &nbsp; &nbsp; &nbsp; $mail->Host = 'smtp.gmail.com;';&nbsp; // Specify main and backup SMTP servers&nbsp; &nbsp; &nbsp; &nbsp; $mail->SMTPAuth = true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Enable SMTP authentication&nbsp; &nbsp; &nbsp; &nbsp; $mail->Username = "your_user_name_or_email@gmail.com";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// SMTP username&nbsp; &nbsp; &nbsp; &nbsp; $mail->Password = "your_user_Password";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// SMTP password&nbsp; &nbsp; &nbsp; &nbsp; // $mail->SMTPSecure = 'tls';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Enable TLS encryption, `ssl` also accepted&nbsp; &nbsp; &nbsp; &nbsp; $mail->Port = 587;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // TCP port to connect to&nbsp; &nbsp; &nbsp; &nbsp; $mail->setFrom("your_user_name_or_email@gmail.com");&nbsp; &nbsp; &nbsp; &nbsp; $mail->addAddress($SendMailTo);&nbsp; &nbsp; &nbsp;// Add a recipient&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Name is optional&nbsp; &nbsp; &nbsp; &nbsp; $mail->addReplyTo("your_user_name_or_email@gmail.com");&nbsp; &nbsp; &nbsp; &nbsp; // $mail->addAttachment('/var/tmp/file.tar.gz');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Add attachments&nbsp; &nbsp; &nbsp; &nbsp; // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');&nbsp; &nbsp; // Optional name&nbsp; &nbsp; &nbsp; &nbsp; $mail->isHTML(true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set email format to HTML&nbsp; &nbsp; &nbsp; &nbsp; ///send custom code in email&nbsp; &nbsp; &nbsp; &nbsp; $code = 242343;&nbsp; &nbsp; &nbsp; &nbsp; $mail->Subject = 'TeachMe verification email';&nbsp; &nbsp; &nbsp; &nbsp; $mail->Body&nbsp; &nbsp; = 'Hi <br><br> <b>Thanks for registeration,Your verification code is </b>'.$code;&nbsp; &nbsp; &nbsp; &nbsp; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';&nbsp; &nbsp; &nbsp; &nbsp; if(!$mail->send()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo 'Message could not be sent.';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo 'Mailer Error: ' . $mail->ErrorInfo;&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo 'Message has been sent';&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; ?></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5