dsgfdgh14569 2013-04-02 20:36
浏览 17
已采纳

用SMTP脚本替换mail()脚本[关闭]

PHP's mail() function has stopped sending my emails. I talked with my service provider and they said I have to use SMTP however i am not professional php developer. They tried to give a little help and they provided me with a script which sends email to me when a user submit a form, but my old form used to send email to me of the clent data as well as a confirmation email email to the client.

The new script i have manged some how to send a confirmation email for the client, but I don't know how send email with this script, can you tell me what I should add to make it work?

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;
    }

}




}

?>

//**** The fifth 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;


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;
    }

}

}

?>

//// **** Sixth update NOW it's working it's working

    <?
    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条回答 默认 最新

  • dqs66973 2013-04-02 21:01
    关注

    if i understand exactly your question. you were able to send the email to your client but you want to send it also to you.

    if this the case then. add another receptionist$mail->AddAddress($visitor_email, "MY_CLIENT");

    EDIT: first get red of the second line.

        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;}}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?