I'm rather inexperienced when it comes to php mail scripts. I've got a working script, thanks to the PHPmailer that everyone uses. But what I want is to modify it so that I send the form info to two locations:
Step one, send all information as text-only to email@location.com
Step two, send the information to a 3rd-party url to process all of the original post data from the form.
But I really have no idea how to modify this script for that. Here's what I have so far:
<?php
require_once '../PHPMailerAutoload.php';
$results_messages = array();
$mail = new PHPMailer(true);
$mail->CharSet = 'utf-8';
class phpmailerAppException extends phpmailerException {}
try {
$to = 'email@website.com';
if(!PHPMailer::validateAddress($to)) {
throw new phpmailerAppException("Email address " . $to . " is invalid -- aborting!");
}
$first_name_field = $_POST['firstName'];
$last_name_field = $_POST['lastName'];
$elq_campaign_id = $_POST['elqCampaignId'];
$company = $_POST['company'];
$businessPhone = $_POST['businessPhone'];
$email_field = $_POST['emailAddress'];
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = "smtp.emailhoster.com";
$mail->Port = "25";
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Username = "email@website.com";
$mail->Password = "passwordhere";
$mail->addReplyTo("email@website.com", "name");
$mail->From = $email_field;
$mail->FromName = "charles1";
$mail->addAddress("email@website.com", "name");
$mail->Subject = "testing emails";
$body = <<<EOT
Test email
$first_name_field $last_name_field <br/>
$elq_campaign_id<br/>
$company<br/>
$businessPhone<br/>
EOT;
$mail->WordWrap = 80;
$mail->msgHTML($body, dirname(__FILE__), true); //Create message bodies and embed images
$mail->addAttachment('images/phpmailer_mini.gif','phpmailer_mini.gif'); // optional name
$mail->addAttachment('images/phpmailer.png', 'phpmailer.png'); // optional name
try {
$mail->send();
$results_messages[] = "Message has been sent using SMTP";
}
catch (phpmailerException $e) {
throw new phpmailerAppException('Unable to send to: ' . $to. ': '.$e->getMessage());
}
}
catch (phpmailerAppException $e) {
$results_messages[] = $e->errorMessage();
}
if (count($results_messages) > 0) {
echo "<h2>Thank you</h2>\n";
echo "<ul>\n";
foreach ($results_messages as $result) {
echo "<li>$result</li>\n";
}
echo "<li>We will contact you as soon as possible</li></ul>\n";
}
?>