Php 在提交注册表时向用户发送邮件
大家好,我正在尝试在用户填写注册表并单击提交按钮后发送邮件。我不知道我做错了什么,但我没有收到任何邮件。请帮帮我Php 在提交注册表时向用户发送邮件,php,html,database,Php,Html,Database,大家好,我正在尝试在用户填写注册表并单击提交按钮后发送邮件。我不知道我做错了什么,但我没有收到任何邮件。请帮帮我 <?php if(isset($_POST['submit'])) { $message= 'Name : ' .$_POST['firstname'].' <br /> '; require "phpmailer/class.phpmailer.php"; //include phpmaile
<?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)
将您的要求更改为:
您的isSMTP()
函数带有大写字母I->isSMTP,请更改为小写字母“I”
添加$mail->isHTML(true)代码>
将$mail->SMTPSecure=“ssl”
更改为$mail->SMTPSecure=HPMailer::ENCRYPTION\u STARTTLS代码>
将端口更改为587
请参阅PHPMailer的GitHub页面上的Gmail示例:
请参阅谷歌文档以确保您在Gmail上的设置正确:
我在某个地方读到,gmail不会接受任何来自php的电子邮件。它将被视为垃圾邮件或类似的东西在上面,你可能需要在你的Gmail控制台中启用“不太安全的应用程序”发送。我有一些VB的东西,通过gmail发送电子邮件,我必须这样做。但是,如果我不启用它,我在尝试发送时确实会收到一条错误消息。您似乎也没有设置“发件人”地址,这可能是一个问题,还是PHPMailer使用默认值?这是否回答了您的问题?我对php邮件非常陌生,任何人都可以一步一步地指导我,因为我不确定我应该从哪里开始我确实像你说的那样做了,但现在我在点击提交按钮后出现了错误pass error:syntax error,C:\Apache\htdocs\register.php中的意外“use”(T_use),第121行use PHPMailer\PHPMailer\PHPMailer;使用PHPMailer\PHPMailer\SMTP;require('PHPMailer/src/PHPMailer.php');要求('PHPMailer/src/SMTP.php');我已经添加了这4行,但现在我得到了错误,它不会消失。请确保您指向正确的PHPMailer目录,并相应地更改这些行。。。use和require语句应位于文件的顶部。
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require('PHPMailer/src/PHPMailer.php');
require('PHPMailer/src/SMTP.php');