我使用php邮件并且我无法指定发件人邮件,我想成为他的电子邮件在这里的每一种类型的变量,但是它无法完成我必须输入我的电子邮件和我的密码,所以任何人知道如何做到这一点
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "usermail"; // GMAIL username
$mail->Password = ""; // GMAIL password
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->addReply=$_POST['email'] ;
$mail->addAddress=$_POST['email'];
$mail->Subject=$_POST['subject'];
$mail->Body=$_POST['message'] .$_POST['email'];
$mail->Sender=$_POST['email'];
答案 0 :(得分:0)
试试这段代码
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "email@gmail.com";
$mail->Password = "password";
$mail->SetFrom("example@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email@gmail.com");
@$mail->Send()
答案 1 :(得分:-5)
通过此链接-> Own-Email-System-using-SMTP-and-PHPMailer
要么,
请详细说明您的问题,以便我可以适当地帮助您。
注意:如果您的Gmail帐户已关闭“缺乏安全的应用程序访问权限”,则必须将其打开。 => Click Here To see . Is it ON or OFF
<?php
require_once 'vendor/autoload.php';
$mail = new PHPMailer\PHPMailer\PHPMailer;
//Enable SMTP debug mode
$mail->SMTPDebug = 0;
//set PHPMailer to use SMTP
$mail->isSMTP();
//set host name
$mail->Host = "smtp.gmail.com";
// set this true if SMTP host requires authentication to send mail
$mail->SMTPAuth = true;
//Provide username & password
$mail->Username = "YOUR_GMAIL_EMAIL_ID";
$mail->Password = "YOUR_GMAIL_PASSWORD";
$mail->SMTPSecure = "tls";
$mail->Port = 587;// Enter port number
$mail->ClearReplyTos();
$mail->addReplyTo("YOUR_GMAIL_EMAIL_ID", $_POST['name']); //$_POST['name'] => YOUR_GMAIL_NAME . You Can directly give "YOUR_GMAIL_NAME"
$mail->SetFrom("YOUR_GMAIL_EMAIL_ID", $_POST['name']);
$mail->addAddress($_POST["email"]); //TO WHOM U R SENDING MAIL
//Subject
$mail->isHTML(true);
$mail->Subject =" ".$_POST['subject']." ";
$body = "<html>
<head> </head>
<body>
".$_POST['message']." <br>
</body>
</html>";
$mail->MsgHTML($body);
if(!$mail->send()) {
$error_message = "Mailer Error : ". $mail->ErrorInfo;
echo $error_message;
} else {
echo "Email Sent Successfully";
}
?>