I am working on an ordering system, which will need to send the customer, distributor and the website owner an email.
The owner and distributor can get the same email (order details etc), but the customer needs one with a slightly different body to incorporate a thank you message.
Currently I have this:
require_once('PHPMailer/class.phpmailer.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "";
$mail->Port = 587; // or 587
//$mail->IsHTML(true);
$mail->Username = "";
$mail->Password = "";
$mail->SetFrom("");
$mail->IsHTML(true);
$mail->Subject = "Online Shop - New Order - " . $orderNumber;
$mail->Body = "A new order has been placed with Online Shop. Please find the delivery details below: <br><br> " . $orderDetails;
$mail->AddAddress($distributerEmail); //Distributor email address
$mail->AddAddress($ownerEmail); //Owner email address
if($mail->Send()){ }else{ $error = "Error sending message! <br/>"; }
How can I reuse the $mail component, to send another email without having to define the server details as well? I
Try this:
require_once 'PHPMailerAutoload.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "";
$mail->Port = 587; // or 587
//$mail->IsHTML(true);
$mail->Username = "";
$mail->Password = "";
$mail->SetFrom("");
$mail->IsHTML(true);
$mail->Subject = "Online Shop - New Order - " . $orderNumber;
$mail->Body = "A new order has been placed with Online Shop. Please find the delivery details below: <br><br> " . $orderDetails;
$mail->AddAddress($distributerEmail); //Distributor email address
$mail->AddAddress($ownerEmail); //Owner email address
if($mail->Send()){ }else{ $error = "Error sending message! <br/>"; }
// We delete the addresses of distributer and owner.
$mail->ClearAddresses();
$mail->AddAddress($customerEmail);
$mail->Body = "new body";
if($mail->Send()){ }else{ $error = "Error sending message! <br/>"; }