php - 在提交注册表单时向用户发送邮件
问题描述
大家好,我正在尝试在用户填写注册表并单击提交按钮后发送邮件。我不知道我做错了什么,但我没有收到任何邮件。请帮我!
<?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)
推荐阅读
- java - 获取实体管理器的适当属性
- python - 如何设置网格线的起始位置?
- oracle - 无法在 Oracle SQL Developer 中创建新连接
- python - django模板变量在
- c# - 如何获取对 WebView2 中新窗口的引用?
- python - 带有Manager的python多处理进程表现得很奇怪
- android - 在 Google Play 商店下载 APP 时出现错误“出现问题。再试一次。”
- hyperledger-fabric - 如何在 Hyperledger Fabric 的链码中获取伪随机数?
- jquery - 单击后更改按钮文本以在加载时加载更多
- sql - Big Query 中的资源超支 - 为什么会发生这种情况?