您好,我已经编写了用于联系邮件功能的代码,一切正常,但是在发送邮件后显示消息为已发送邮件的问题无法重定向另一个页面。
<?php
require_once('class.phpmailer.php');
// include("class.smtp.php"); // optional, gets called from within
class.phpmailer.php if not already loaded
$name = $_POST['form_name'];
$email = $_POST['form_email'];
$phone = $_POST['form_phone'];
$subject = $_POST['form_subject'];
$messages = $_POST['form_message'];
$mail = new PHPMailer();
$smtp_host = "HOST";
$smtp_user = "USER";
$smtp_password = "SECRET";
$smtp_port = "25";
$mail_from = $email;
$mail_to = "MAILTO";
$mail_to_name = "MAILNAME";
$message = array();
$message[]= 'Name : '.trim($name).' ';
$message[]='Phone : '.trim($phone).' ';
$message[]='Email : '.trim($email).' ';
$message[]='Message : '.trim($messages).' ';
$message = implode('<br/>', $message);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "{$smtp_host}"; // 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->Host = "{$smtp_host}"; // sets the SMTP server
$mail->Port = $smtp_port; // set the SMTP port for the GMAIL server
$mail->Username = "{$smtp_user}"; // SMTP account username
$mail->Password = "{$smtp_password}"; // SMTP account password
$mail->SetFrom("{$mail_from}", "{$mail_from_name}");
$mail->Subject = "$subject";
$mail->MsgHTML($message);
$address = "{$mail_to}";
$mail->AddAddress($address, "{$mail_to_name}" );
if(!$mail->Send()) {
echo "Error while sending email";
} else {
echo "message sent";
header("Location:contact.html");
}
我遇到此错误:
SMTP -> FROM SERVER:220-cp.rdsindia.in ESMTP Exim 4.91 #1 Tue, 19 Mar 2019 18:45:10 +0530 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
SMTP -> FROM SERVER: 250-cp.rdsindia.in Hello rdaconsulting.in [64.62.254.150] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP
SMTP -> FROM SERVER:250 OK
SMTP -> FROM SERVER:250 Accepted
SMTP -> FROM SERVER:354 Enter message, ending with "." on a line by itself
SMTP -> FROM SERVER:250 OK id=1h6EaE-0005nk-5J
SMTP -> FROM SERVER:221 cp.rdsindia.in closing connection
答案 0 :(得分:0)
<?php
require_once('class.phpmailer.php');
// include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$name = $_POST['form_name'];
$email = $_POST['form_email'];
$phone = $_POST['form_phone'];
$subject = $_POST['form_subject'];
$messages = $_POST['form_message'];
$mail = new PHPMailer();
$smtp_host = "domain.in";
$smtp_user = "info@gmail.in";
$smtp_password = "12%^&*";
$smtp_port = "25";
$mail_from = $email;
$mail_from_name = $name ;
$mail_to = "mail@gmail.in";
$mail_to_name = "Ronsulting";
$message = array();
$message[]= 'Name : '.trim($name).' ';
$message[]='Phone : '.trim($phone).' ';
$message[]='Email : '.trim($email).' ';
$message[]='Message : '.trim($messages).' ';
$message = implode('<br/>', $message);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "{$smtp_host}"; // SMTP server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "{$smtp_host}"; // sets the SMTP server
$mail->Port = $smtp_port; // set the SMTP port for the GMAIL server
$mail->Username = "{$smtp_user}"; // SMTP account username
$mail->Password = "{$smtp_password}"; // SMTP account password
$mail->SetFrom("{$mail_from}", "{$mail_from_name}");
$mail->Subject = "$subject";
$mail->MsgHTML($message);
$address = "{$mail_to}";
$mail->AddAddress($address, "{$mail_to_name}" );
if(!$mail->Send()) {
echo "Error while sending email";
} else {
header('Location:contact.html');
}
echo "<script type='text/javascript'>window.location.href='http://domain.in/contact.html'</scrip
t>";