在提交注册表格时向用户发送邮件



大家好,我正在尝试在用户填写注册表并单击提交按钮后发送邮件。我不知道我做错了什么,但我没有收到任何邮件。请帮帮我!

<?php
if(isset($_POST['submit'])) 
{
$message=
'Name           :   ' .$_POST['firstname'].'        <br />
';
require "phpmailer/class.phpmailer.php"; //include phpmailer class

// Instantiate Class  
$mail = new PHPMailer();  

// Set up SMTP  
$mail->IsSMTP();                // Sets up a SMTP connection  
$mail->SMTPAuth = true;         // Connection with the SMTP does require authorization    
$mail->SMTPSecure = "ssl";      // Connect using a TLS connection  
$mail->Host = "smtp.gmail.com";  //Gmail SMTP server address
$mail->Port = 465;  //Gmail SMTP port
$mail->Encoding = '7bit';

// Authentication  
$mail->Username   = "holla@gmail.com"; // Your full Gmail address
$mail->Password   = "blablabla"; // Your Gmail password

// Compose
$mail->Subject = "New Admission Enquiry Form";      // Subject (which isn't required)  
$mail->MsgHTML($message);

// Send To  

$mail->AddAddress("jaganrao44@gmail.com", "Recipient Name"); // Where to send it - Recipient






$result = $mail->Send();        // Send!  
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';      
}
?>

你没有放这个:

$mail->charSet="UTF-8"; //for me it's utf-8
$mail->from="holla@gmail.com";

还要检查您的端口是否打开(465((您也可以尝试25或587(

  1. 将您的需求更改为:
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;

require('PHPMailer/src/PHPMailer.php');
require('PHPMailer/src/SMTP.php');
  1. 您的isSMTP()函数带有大写I->IsSMTP,更改为小写"i">
  2. 添加$mail->isHTML(true);
  3. $mail->SMTPSecure = "ssl"更改为$mail->SMTPSecure = HPMailer::ENCRYPTION_STARTTLS;
  4. 将端口更改为587

请参阅PHPMailer的Gmail GitHub页面上的示例:https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps

请参阅谷歌文档以确保您在Gmail上的设置正确无误:https://support.google.com/mail/answer/7126229?hl=en

相关内容