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

?>

You could just send it as a bcc

$mail->AddBCC("foo@email.com", "test");

But would that work? I don't want to send to a second email. After my email is sent to the first location, I need to send all the $_POST data to a url: action="https://website.com" ...I guess, some way of reposting the original data?

I misunderstood at first read, so this really has nothing to do with PHPmailer since you don't actually want to send another email?

The only way off the top of my head that I can think of to send out data to a 3rd party url would maybe be to use cURL to post the data.

Here's an example http://davidwalsh.name/curl-post

Member Avatar for LastMitch

But would that work? I don't want to send to a second email. After my email is sent to the first location, I need to send all the $_POST data to a url: action="https://website.com" ...I guess, some way of reposting the original data?

@turpentyne

What pixelsoul mention is correct & properly done.

You are trying to manipulative the code, so that the third party email can go to Yahoo, Google, and other emails accounts?

Am I correct?

Yeah, I wanted it to go to an email that is then parsed for a database. I've actually found a different route. The third party software has a component for reposting the info to a url (formmail script) I bet it's some sort of cURL solution they're using.

Thanks!

maybe a quick follow-up question, though.

The script of the original post is to send html. I need plaintext.

I tried changing this line:
$mail->msgHTML($body, dirname(__FILE__), true);

to this: $mail->Body =($body, dirname(__FILE__), true);

but no luck.

oh, wait.. got it

$mail->Body = $body;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.