用SMTP脚本替换mail()脚本

时间:2013-04-02 20:37:00

标签: php smtp

PHP的mail()功能已停止发送我的电子邮件。我和我的服务提供商谈过,他们说我必须使用SMTP,但我不是专业的php开发人员。他们试图给予一些帮助,他们向我提供了一个脚本,当用户提交表单时,该脚本会向我发送电子邮件,但我的旧表单用于向我发送有关数据的电子邮件以及向客户发送的确认电子邮件

新脚本我已经管理了一些如何为客户端发送确认电子邮件,但我不知道如何使用此脚本发送电子邮件,您能告诉我应该添加哪些内容以使其正常工作吗?

if(isset($_POST['submit']))

{

$title         = $_POST['title'];
$name          = $_POST['name'];
$surname       = $_POST['surname'];
$phone         = $_POST['phone'];
$visitor_email = $_POST['email'];
$address       = $_POST['address'];
$postcode      = $_POST['postcode'];
$state         = $_POST['us'];
$details       = $_POST['details'];
$reasons       = $_POST['re'];
$content       = $_POST['message'];

require("class.phpmailer.php");

$mail = new PHPMailer();

//Your SMTP servers details

// set mailer to use SMTP
$mail->IsSMTP();

// specify main and backup server or localhost / your mail server yourmailserver.com
$mail->Host = "xxxxxx.example.com";  

// turn on SMTP authentication
$mail->SMTPAuth = true;     

// SMTP username
$mail->Username = "me@xxxxx.com";  

$mail->Password = "**********"; // SMTP password
//It should be same as that of the SMTP user

$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form

//$mail->From = $mail->Username;    //Default From email same as smtp user
$mail->FromName = "Admin";

//Email address where you wish to receive/collect those emails.
$mail->AddAddress($visitor_email, ""); 

$mail->WordWrap = 50;// set word wrap to 50 characters
$mail->IsHTML(true);// set email format to HTML

$mail->Subject = 'You have mail from: www.example.com';


// ** Build the Message
$message = "<h4><b>We received your query</b></h4><br/><br/>";
$message .="Thankyou for contacting example.net.<br/>";
$message .="<br>";
$message .="Regards,<br/>";
$message .="admin";



$mail->Body    = $message;

//header("Location: thank-you.html");
if(!$mail->Send())
{
    header('Location: thank-you.html');
  // echo "Message could not be sent. <p>";
  // echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

header('Location: thank-you.html');



}
else{
    header('Location:  contact-us.html');   
}
?>




// ******** Second update 
<?
ob_start();
if(isset($_POST['submit']))

{

$title         = $_POST['title'];
$name          = $_POST['name'];
$surname       = $_POST['surname'];
$phone         = $_POST['phone'];
$visitor_email = $_POST['email'];
$address       = $_POST['address'];
$postcode      = $_POST['postcode'];
$state         = $_POST['us'];
$details       = $_POST['details'];
$reasons       = $_POST['re'];
$content       = $_POST['message'];

require("class.phpmailer.php");

$mail = new PHPMailer();

//Your SMTP servers details

// set mailer to use SMTP
$mail->IsSMTP();

// specify main and backup server or localhost / your mail server yourmailserver.com
$mail->Host = "xxx.example.net";  

// turn on SMTP authentication
$mail->SMTPAuth = true;     

// SMTP username
$mail->Username = "*****@example.net";  

$mail->Password = "********"; // SMTP password
//It should be same as that of the SMTP user

$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form

//$mail->From = $mail->Username;    //Default From email same as smtp user
$mail->FromName = "Admin vueproperty";

$mail->AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
//$mail->AddCC($_POST['email']); // ** Client email
$mail->WordWrap = 50;// set word wrap to 50 characters
$mail->IsHTML(true);// set email format to HTML

$mail->Subject = 'You have mail from: www.exmple.net';


// ** Build the Message
$message = "<h4><b>We received your query</b></h4><br/><br/>";
$message .="Thank you for contacting example.net.  A property consultant will be in contact with you asap.<br/>";
$message .="<br>";
$message .="Regards,<br/>";
$message .="The example Team";



$mail->Body    = $message;

//header("Location: thank-you.html");

if($mail->Send())
{
    $body  = "Name: $name<br/>";
    $body .= "Phone: $phone<br/>";
    $body .= "Email: $visitor_email<br/>";
    $mail->AddAddress('xphpxmysql@gmail.com', "MINE");
    if($mail->Send()){
        header('Location: thank-you.html');
        exit;
    }
}





}

?>
// ******** Third update 
<?
ob_start();
if(isset($_POST['submit']))

{

$title         = $_POST['title'];
$name          = $_POST['name'];
$surname       = $_POST['surname'];
$phone         = $_POST['phone'];
$visitor_email = $_POST['email'];
$address       = $_POST['address'];
$postcode      = $_POST['postcode'];
$state         = $_POST['us'];
$details       = $_POST['details'];
$reasons       = $_POST['re'];
$content       = $_POST['message'];

require("class.phpmailer.php");

$mail = new PHPMailer();

//Your SMTP servers details

// set mailer to use SMTP
$mail->IsSMTP();

// specify main and backup server or localhost / your mail server yourmailserver.com
$mail->Host = "xxx.example.net";  

// turn on SMTP authentication
$mail->SMTPAuth = true;     

// SMTP username
$mail->Username = "*****@example.net";  

$mail->Password = "********"; // SMTP password
//It should be same as that of the SMTP user

$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form

//$mail->From = $mail->Username;    //Default From email same as smtp user
$mail->FromName = "Admin vueproperty";

$mail->AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
//$mail->AddCC($_POST['email']); // ** Client email
$mail->WordWrap = 50;// set word wrap to 50 characters
$mail->IsHTML(true);// set email format to HTML

$mail->Subject = 'You have mail from: www.exmple.net';


// ** Build the Message
$message = "<h4><b>We received your query</b></h4><br/><br/>";
$message .="Thank you for contacting example.net.  A property consultant will be in contact with you asap.<br/>";
$message .="<br>";
$message .="Regards,<br/>";
$message .="The example Team";



$mail->Body    = $message;

//header("Location: thank-you.html");

if($mail->Send())
{
    $body = "Name: " . $name . "<br/>"; 
    $body .= "Phone: " . $phone . "<br/>"; 
    $body .= "Email: ". $visitor_email . "<br/>"; 
    $mail->body = $body; 
    $mail->AddAddress('xphpxmysql@gmail.com', "MINE"); 
    if($mail->Send())
    {
        header('Location: thank-you.html'); 
        exit;
    }

}




}

?>

// * *** 第五次更新

<?
ob_start();
if(isset($_POST['submit']))

{

$title         = $_POST['title'];
$name          = $_POST['name'];
$surname       = $_POST['surname'];
$phone         = $_POST['phone'];
$visitor_email = $_POST['email'];
$address       = $_POST['address'];
$postcode      = $_POST['postcode'];
$state         = $_POST['us'];
$details       = $_POST['details'];
$reasons       = $_POST['re'];
$content       = $_POST['message'];

require("class.phpmailer.php");

$mail = new PHPMailer();

//Your SMTP servers details

// set mailer to use SMTP
$mail->IsSMTP();

// specify main and backup server or localhost / your mail server yourmailserver.com
$mail->Host = "xxx.example.net";  

// turn on SMTP authentication
$mail->SMTPAuth = true;     

// SMTP username
$mail->Username = "*****@example.net";  

$mail->Password = "********"; // SMTP password
//It should be same as that of the SMTP user

$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form

//$mail->From = $mail->Username;    //Default From email same as smtp user
$mail->FromName = "Admin vueproperty";

$mail->AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
//$mail->AddCC($_POST['email']); // ** Client email
$mail->WordWrap = 50;// set word wrap to 50 characters
$mail->IsHTML(true);// set email format to HTML

$mail->Subject = 'You have mail from: www.exmple.net';


// ** Build the Message
$message = "<h4><b>We received your query</b></h4><br/><br/>";
$message .="Thank you for contacting example.net.  A property consultant will be in contact with you asap.<br/>";
$message .="<br>";
$message .="Regards,<br/>";
$message .="The example Team";



$mail->Body    = $message;


if($mail->Send())
{
    $body = "Name: " . $name . "<br/>"; 
    $body .= "Phone: " . $phone . "<br/>"; 
    $body .= "Email: ". $visitor_email . "<br/>"; 
    $mail->Body = $body; 
    $mail->AddAddress('xphpxmysql@gmail.com', "MINE"); 
    if($mail->Send())
    {
        header('Location: thank-you.html'); 
        exit;
    }

}

}

?>

//// * ** * 第六次更新现在它正在运作

    <?
    ob_start();
    if(isset($_POST['submit']))

    {

    $title         = $_POST['title'];
    $name          = $_POST['name'];
    $surname       = $_POST['surname'];
    $phone         = $_POST['phone'];
    $visitor_email = $_POST['email'];
    $address       = $_POST['address'];
    $postcode      = $_POST['postcode'];
    $state         = $_POST['us'];
    $details       = $_POST['details'];
    $reasons       = $_POST['re'];
    $content       = $_POST['message'];

    require("class.phpmailer.php");

    $mail = new PHPMailer();

    //Your SMTP servers details

    // set mailer to use SMTP
    $mail->IsSMTP();

    // specify main and backup server or localhost / your mail server yourmailserver.com
    $mail->Host = "xxx.example.net";  

    // turn on SMTP authentication
    $mail->SMTPAuth = true;     

    // SMTP username
    $mail->Username = "*****@example.net";  

    $mail->Password = "********"; // SMTP password
    //It should be same as that of the SMTP user

    $redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form

    //$mail->From = $mail->Username;    //Default From email same as smtp user
    $mail->FromName = "Admin vueproperty";

    $mail->AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
    //$mail->AddCC($_POST['email']); // ** Client email
    $mail->WordWrap = 50;// set word wrap to 50 characters
    $mail->IsHTML(true);// set email format to HTML

    $mail->Subject = 'You have mail from: www.exmple.net';


    // ** Build the Message
    $message = "<h4><b>We received your query</b></h4><br/><br/>";
    $message .="Thank you for contacting example.net.  A property consultant will be in contact with you asap.<br/>";
    $message .="<br>";
    $message .="Regards,<br/>";
    $message .="The example Team";



    $mail->Body    = $message;

    $mail->Send();
        $mail->ClearAllRecipients();
        $body = "Name: " . $name . "<br/>"; 
        $body .= "Phone: " . $phone . "<br/>"; 
        $body .= "Email: ". $visitor_email . "<br/>"; 
        $mail->Body = $body; 
        $mail->AddAddress('xphpxmysql@gmail.com', ""); 
        if($mail->Send())
        {
        $mail->ClearAllRecipients();
        header('Location: thank-you.html'); 
        exit;
    }

}

1 个答案:

答案 0 :(得分:1)

如果我完全理解你的问题。您可以将电子邮件发送给您的客户,但您也想将其发送给您。

如果是这样的话。添加另一名接待员$mail->AddAddress($visitor_email, "MY_CLIENT");

编辑: 首先得到第二行的红色。

    if($mail->Send()){$message = "ALL REQUIRED DATA YOU WANT TO SEND TO YOURSELF";$mail->AddAddress('YOUREMAIL@EXAMPLE.COM', "MINE");if($mail->Send()){header('Location: thank-you.html');exit;}}