-2

I've inherited an email form from a former vendor and after we've moved it to it's new server it started to malfunction. What it's supposed to do is send a verification email to the user who filled it out (does this), then send an email to warranty@mydomain.com and bcc: another address (this it no longer does). Tried everything but I'm not super savvy with PHP, mostly a front-end coder, can anyone look at my code and tell me why this isn't sending properly?

PHP code:

<?php
header("location: http://www.anatomicglobal.com/warranty/regthanks.html");

$posting = array(
    'Name'      =>  $_POST['Name'],
    'Email'     =>  $_POST['Email'],
    'Phone'     =>  $_POST['Phone'],
    'Address'   =>  $_POST['Address'],
    'City'      =>  $_POST['City'],
    'State'     =>  $_POST['State'],
    'Province'  =>  $_POST['Province'],
    'Zip'       =>  $_POST['Zip'],
    'Product'   =>  $_POST['check'][0],
    'Size'      =>  $_POST['size'][0],
    'Mattress Model Name'   =>  $_POST['MattressModeName'],
    'Mattress Model Number' =>  $_POST['MattressModeNo'],
    'Serial Number' =>  $_POST['SerialNumber'],
    'Store Name'    =>  $_POST['StoreName'],
    'Purchase Month'=>  $_POST['Month'],
    'Purchase Day'  =>  $_POST['Day'],
    'Purchase Year' =>  $_POST['Year']
);

$decide = $_POST['decide'];

$subject  = 'Eco Memory Foam - Warranty Registration';
$to   = 'warranty@anatomicglobal.com';
$to   = $posting['Email'];

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'To: Anatomic Global <warranty@anatomicglobal.com>' . "\r\n";
$headers .= 'From: ecomemoryfoam.com <warranty@anatomicglobal.com>' . "\r\n";
$headers .= 'Reply-To: ' . $posting['Email'] . "\r\n";
$headers .= 'bcc: Hollyce Weber <hweber@anatomicglobal.com>' . "\r\n";

$message  = '<html>';
$message .= '<head><title>Eco Memory Foam - Warranty Registration</title></head><body>';
$message .= '<h1>Eco Memory Foam - Warranty Registration</h1>';
$message .= '<p><strong>Warranty Registration</strong> submission successful, please keep for your records.</p>
';
$message .= '<p>Below is the submitted information at: <strong>' . strftime("%B %d %Y - %H:%M:%S", time()) . '</strong></p>';
$message .= '<dl>';

foreach ($posting as $field => $value) {
$message .= '<dt>';
$message .= '<dd><b>' . $field . '</b>:&nbsp;&nbsp;' . $value . '</dd>';
$message .= '</dt>';
};

$message .= '<dt>Decide to Purchase This Product?</dt>';
$message .= '<dd>Customer Selected:<ul>';
foreach ($decide as $field => $value) {
$message .= '<li>' . $value . '</li>';
};
$message .= '</ul></dd>';

$message .= '</dl>';
/**$message .= '<p>You can reply to the submitter by replying to this email (if they gave you a valid email address).</p></body></html>';**/

mail($to, $subject, $message, $headers);

a few hours later....

Thanks for the help guys, but it's still not sending anything, the new code looks like this:

<?php

$posting = array(
    'Name'      =>  $_POST['Name'],
    'Email'     =>  $_POST['Email'],
    'Phone'     =>  $_POST['Phone'],
    'Address'   =>  $_POST['Address'],
    'City'      =>  $_POST['City'],
    'State'     =>  $_POST['State'],
    'Province'  =>  $_POST['Province'],
    'Zip'       =>  $_POST['Zip'],
    'Product'   =>  $_POST['check'][0],
    'Size'      =>  $_POST['size'][0],
    'Mattress Model Name'   =>  $_POST['MattressModeName'],
    'Mattress Model Number' =>  $_POST['MattressModeNo'],
    'Serial Number' =>  $_POST['SerialNumber'],
    'Store Name'    =>  $_POST['StoreName'],
    'Purchase Month'=>  $_POST['Month'],
    'Purchase Day'  =>  $_POST['Day'],
    'Purchase Year' =>  $_POST['Year']
);

$decide = $_POST['decide'];

$subject  = 'Eco Memory Foam - Warranty Registration';
$to   = "warranty@anatomicglobal.com, {$posting['email']}";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'To: Anatomic Global <warranty@anatomicglobal.com>' . "\r\n";
$headers .= 'From: ecomemoryfoam.com <warranty@anatomicglobal.com>' . "\r\n";
$headers .= 'Reply-To: ' . $posting['Email'] . "\r\n";
$headers .= 'bcc: Hollyce Weber <hweber@anatomicglobal.com>' . "\r\n";

$message  = '<html>';
$message .= '<head><title>Eco Memory Foam - Warranty Registration</title></head><body>';
$message .= '<h1>Eco Memory Foam - Warranty Registration</h1>';
$message .= '<p><strong>Warranty Registration</strong> submission successful, please keep for your records.</p>
';
$message .= '<p>Below is the submitted information at: <strong>' . strftime("%B %d %Y - %H:%M:%S", time()) . '</strong></p>';
$message .= '<dl>';

foreach ($posting as $field => $value) {
$message .= '<dt>';
$message .= '<dd><b>' . $field . '</b>:&nbsp;&nbsp;' . $value . '</dd>';
$message .= '</dt>';
};

$message .= '<dt>Decide to Purchase This Product?</dt>';
$message .= '<dd>Customer Selected:<ul>';
foreach ($decide as $field => $value) {
$message .= '<li>' . $value . '</li>';
};
$message .= '</ul></dd>';

$message .= '</dl>';
/**$message .= '<p>You can reply to the submitter by replying to this email (if they gave you a valid email address).</p></body></html>';**/

mail($to, $subject, $message, $headers);

header("location: http://www.anatomicglobal.com/warranty/regthanks.html");

2 Answers2

1

put

header("location: http://www.anatomicglobal.com/warranty/regthanks.html");

at the end...

Vincent MAURY
  • 253
  • 2
  • 5
  • Please read [Why I have to call 'exit' after redirection through header('Location..') in PHP?](http://stackoverflow.com/questions/2747791/why-i-have-to-call-exit-after-redirection-through-headerlocation-in-php) -- How his code is, your suggestion is not needed – UnholyRanger Mar 13 '13 at 15:59
  • moved it to the bottom, but it seems that's not the problem. hmm. Thanks for helping. :) – zodwallopp Mar 13 '13 at 17:40
0

In your code, you have it so it is sending the email to only one address. Here you're building your to adress:

$to   = 'warranty@domain.com';
$to   = $posting['Email'];

If you notice, you're setting the address to yours then overwriting it with the posted email. Then you go on to email it to only the one address

mail($to, $subject, $message, $headers);

You need to build the addresses as such:

$to = "warranty@domain.com, {$posting['email']}";

this will have the following value:

"warranty@domain.com, other@domain.com"
UnholyRanger
  • 1,977
  • 14
  • 24
  • Ok, I've done that but now it's not sending anything at all... sigh. This thing is frustrating, thanks for your help though. The code now looks like this: – zodwallopp Mar 13 '13 at 17:41
  • put this at the top: `error_reporting(E_ALL); ini_set("display_errors", 1);` it will display any errors. Also, to test values of variables, try `echo`ing them out or `var_dump($variable)` – UnholyRanger Mar 13 '13 at 17:45