当我尝试在云端测试电子邮件时,phpmailer 给出 HTTP ERROR 500
phpmailer gives HTTP ERROR 500 when i try to test email on cloudways
我是网络开发的新手。我写了一个 php 代码来从表单发送电子邮件,并将它托管在云端。每当我点击提交按钮时,我都会收到 HTTP 错误 500。
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
# code...
$name = trim($_POST["fullname"]);
$email = trim($_POST["email"]);
$phone_no = trim($_POST["phone_num"]);
$partner_type = $_POST["Partner_type"];
if ($name == "" || $email == "" || $phone_no == " ") {
echo "please fill the required fields name , email , phone number";
}
if ($_POST["adds"] != "") {
echo "Bad form input";
exit;
}
require 'class.phpmailer.php';
$mail = new PHPMailer();
if (!$mail->ValidateAddress($email)) {
# code...
echo "Invalid Email Address";
exit;
}
$email_body = "";
$email_body .= "Name " . $name . "\n";
$email_body .= "Email " . $email . "\n";
$email_body .= "Phone Number " . $phone_no . "\n";
$email_body .= "Partner Type " . $partner_type . "\n";
$mail->setFrom($email, $name);
$mail->addAddress('rescuetl@localhost', 'gbubemi'); // Add a recipient
/**$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
**/
$mail->isHTML(false); // Set email format to HTML
$mail->Subject = 'Become a Partner ' . $name ;
$mail->Body = $email_body;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
} else {
echo 'Message has been sent';
}
header("location:index.php?status=thanks");
}
?>
拜托,我真的很沮丧,我需要帮助。谢谢
您应该使用包中的函数 PHPMailerAutoload ..它很简单并且工作得很好。我自己在一个项目中使用它。而且,还很容易被同化。
function sendMail($destinaire, $code, $prename){
require 'phpmailer/PHPMailerAutoload.php';
$userMail = $destinataire; //Recipient
$mail = new PHPMailer();
$mail->Host = "smtp.gmail.com";
$mail->isSMTP();
$success_send = " Le code de reservation a éte envoyé à ".$userMail;
$failed_send = "Echec: le mail in not send verifier votre email";
//On ouvre l'authentification
$mail->SMTPAuth = true;
//Les creditentials
$mail->Username = "Sender@gmail.com";
$mail->Password = "Senderpass";
//set the type of protection
$mail->SMTPSecure ="ssl"; //tls
//Definissons un port
$mail->Port ="465"; //587 pour tls
//L'objet du message
$mail->Subject ="Reservation enregistré";
//Le message en lui meme, afin le contenu quoi
$mail->Body ="Bonjour '.$prename.' Nous avons enregistré votre reservation.
Veuillez presenter le Code suivant le jour du voyage ".$code;
//Bref, qui envoi?
$mail->setFrom('sender@gmail.com', 'Indiza - Travel Dimension');
//set where we are sending this email(à qui)
$mail->addAddress($userMail);
//Envoyer l'email
if($mail->send())
return $success_send;
else
return $failed_send;
}
实用程序
首先(如果您使用 Gmail)您应该降低发送邮件的帐户的安全级别
https://support.google.com/accounts/answer/6010255?hl=en
如果有必要,这个link会很有用Codingpassive/PHPMailer
像这样调用一个函数
$idz = sendMail("$receiverMail","anyCode","receiverName");
真的是电脑吗?没有君子,我们做工艺品。
什么是信息化? Non mon ami, on fait juste du bricolage.
首先,您需要调试应用程序天气电子邮件是否正在发送,或者它是否卡在队列中。您可以在终端上通过 运行 "mailq" 检查它。接下来首先尝试像这样在 Cloudways 上发送简单的电子邮件:
<?php
require_once "vendor/autoload.php"; //PHPMailer Object
$mail = new PHPMailer; //From email address and name
$mail->From = "from@yourdomain.com";
$mail->FromName = "Full Name"; //To address and name
$mail->addAddress("recepient1@example.com", "Recepient Name");//Recipient name is optional
$mail->addAddress("recepient1@example.com"); //Address to which recipient will reply
$mail->addReplyTo("reply@yourdomain.com", "Reply"); //CC and BCC
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com"); //Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else { echo "Message has been sent successfully";
}
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
如果成功并发送了电子邮件,请尝试通过应用 smtp 凭据进行发送,如下所示:
<?php
require_once "vendor/autoload.php";
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "name@gmail.com";
$mail->Password = "super_secret_password";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "name@gmail.com";
$mail->FromName = "Full Name";
$mail->addAddress("name@example.com", "Recepient Name");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
您也可以在Cloudways平台的服务器设置中设置Smtp:
在此处阅读全文:https://www.cloudways.com/blog/send-emails-in-php-using-phpmailer/
我是网络开发的新手。我写了一个 php 代码来从表单发送电子邮件,并将它托管在云端。每当我点击提交按钮时,我都会收到 HTTP 错误 500。
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
# code...
$name = trim($_POST["fullname"]);
$email = trim($_POST["email"]);
$phone_no = trim($_POST["phone_num"]);
$partner_type = $_POST["Partner_type"];
if ($name == "" || $email == "" || $phone_no == " ") {
echo "please fill the required fields name , email , phone number";
}
if ($_POST["adds"] != "") {
echo "Bad form input";
exit;
}
require 'class.phpmailer.php';
$mail = new PHPMailer();
if (!$mail->ValidateAddress($email)) {
# code...
echo "Invalid Email Address";
exit;
}
$email_body = "";
$email_body .= "Name " . $name . "\n";
$email_body .= "Email " . $email . "\n";
$email_body .= "Phone Number " . $phone_no . "\n";
$email_body .= "Partner Type " . $partner_type . "\n";
$mail->setFrom($email, $name);
$mail->addAddress('rescuetl@localhost', 'gbubemi'); // Add a recipient
/**$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
**/
$mail->isHTML(false); // Set email format to HTML
$mail->Subject = 'Become a Partner ' . $name ;
$mail->Body = $email_body;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
} else {
echo 'Message has been sent';
}
header("location:index.php?status=thanks");
}
?>
拜托,我真的很沮丧,我需要帮助。谢谢
您应该使用包中的函数 PHPMailerAutoload ..它很简单并且工作得很好。我自己在一个项目中使用它。而且,还很容易被同化。
function sendMail($destinaire, $code, $prename){
require 'phpmailer/PHPMailerAutoload.php';
$userMail = $destinataire; //Recipient
$mail = new PHPMailer();
$mail->Host = "smtp.gmail.com";
$mail->isSMTP();
$success_send = " Le code de reservation a éte envoyé à ".$userMail;
$failed_send = "Echec: le mail in not send verifier votre email";
//On ouvre l'authentification
$mail->SMTPAuth = true;
//Les creditentials
$mail->Username = "Sender@gmail.com";
$mail->Password = "Senderpass";
//set the type of protection
$mail->SMTPSecure ="ssl"; //tls
//Definissons un port
$mail->Port ="465"; //587 pour tls
//L'objet du message
$mail->Subject ="Reservation enregistré";
//Le message en lui meme, afin le contenu quoi
$mail->Body ="Bonjour '.$prename.' Nous avons enregistré votre reservation.
Veuillez presenter le Code suivant le jour du voyage ".$code;
//Bref, qui envoi?
$mail->setFrom('sender@gmail.com', 'Indiza - Travel Dimension');
//set where we are sending this email(à qui)
$mail->addAddress($userMail);
//Envoyer l'email
if($mail->send())
return $success_send;
else
return $failed_send;
}
实用程序
首先(如果您使用 Gmail)您应该降低发送邮件的帐户的安全级别
https://support.google.com/accounts/answer/6010255?hl=en
如果有必要,这个link会很有用Codingpassive/PHPMailer
像这样调用一个函数
$idz = sendMail("$receiverMail","anyCode","receiverName");
真的是电脑吗?没有君子,我们做工艺品。
什么是信息化? Non mon ami, on fait juste du bricolage.
首先,您需要调试应用程序天气电子邮件是否正在发送,或者它是否卡在队列中。您可以在终端上通过 运行 "mailq" 检查它。接下来首先尝试像这样在 Cloudways 上发送简单的电子邮件:
<?php
require_once "vendor/autoload.php"; //PHPMailer Object
$mail = new PHPMailer; //From email address and name
$mail->From = "from@yourdomain.com";
$mail->FromName = "Full Name"; //To address and name
$mail->addAddress("recepient1@example.com", "Recepient Name");//Recipient name is optional
$mail->addAddress("recepient1@example.com"); //Address to which recipient will reply
$mail->addReplyTo("reply@yourdomain.com", "Reply"); //CC and BCC
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com"); //Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else { echo "Message has been sent successfully";
}
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
如果成功并发送了电子邮件,请尝试通过应用 smtp 凭据进行发送,如下所示:
<?php
require_once "vendor/autoload.php";
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "name@gmail.com";
$mail->Password = "super_secret_password";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "name@gmail.com";
$mail->FromName = "Full Name";
$mail->addAddress("name@example.com", "Recepient Name");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
您也可以在Cloudways平台的服务器设置中设置Smtp:
在此处阅读全文:https://www.cloudways.com/blog/send-emails-in-php-using-phpmailer/