首页 > 解决方案 > 在提交注册表单时向用户发送邮件

问题描述

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

<?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!';      

}
?>

标签: phphtmldatabase

解决方案


你没有放这个:

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

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


推荐阅读