0

I need a form to send to multiple different receipients based off the user dropdown selection. Here is what I've read up on so far... I can get it to say success but I dont recieve the email. Please help!!

Html:

<select id="sendto" class="css-select" name="sendto">
<option id="sales" value="gmail" name="sendto">Gmail</option>
<option id="support" value="yahoo" name="sendto">yahoo</option>
</select>

PHP:

<?php

$i = $_POST["sendto"];
switch ($i) {
case "gmail":
    $sendto = "gmail@gmail.com";
    break;
case "recpro":
    $sendto = "yahoo@yahoo.com";
    break;
default:
    $sendto = "gmail@gmail.com"; //opional
    break;
} 

function sanitize( $s ){
$injections = array('/(\n+)/i',
'/(\r+)/i',
'/(\t+)/i',
'/(%0A+)/i',
'/(%0D+)/i',
'/(%08+)/i',
'/(%09+)/i'
);
$s = preg_replace( $injections, '', $s );

return $s;
}  
//catch the posted data
$first_name = sanitize( $_POST['first_name'] );
$last_name = sanitize( $_POST['last_name'] );
$email = sanitize( $_POST['email'] );
$telephone = sanitize( $_POST['telelphone'] );

$body = $telephone."\n\n";
$body.= $first_name."<$email>";
$headers = "From: $last_name<$email>";

if(mail($send_to, $subject, $body, $headers)):
echo "success";
else:
echo "error";
endif;
?>

I need it to be header injection safe.

Darren
  • 13,050
  • 4
  • 41
  • 79
davisge2
  • 1
  • 3
  • Have you tried `echo $send_to, $subject, $body, $headers` to see if variables all correct and have data? Also are you sending this from your web server or localhost? – Onimusha Jul 18 '14 at 02:05
  • I'll add echo. Sending from web server. – davisge2 Jul 18 '14 at 09:36
  • added subject line $subject = "test email"; and if(mail($send_to, $subject, $body, $headers)): echo "success", $sent_to, $subject, $body, $headers; – davisge2 Jul 18 '14 at 13:19
  • but the echo only shows "success, subject, $body,$headers" no email any ideas why the switch and $email_to isnt working? – davisge2 Jul 18 '14 at 13:20

1 Answers1

0

I just changed

$i = $_POST["sendto"]; switch ($i) { case "gmail": $sendto = "gmail@gmail.com"; break; case "recpro": $sendto = "yahoo@yahoo.com"; break; default: $sendto = "gmail@gmail.com"; //opional break; }

to this

$i = $_POST["sendto"]; if ($i == "gmail"){ $sendto = "gmail@gmail.com"; } elseif ($i == "yahoo") { $sendto = "gmail@yahoo.com"; } else { $sendto = "gmail@gmail.com"; }

and mail section to this:

`

$headers = "From: " . strip_tags($_POST['your-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['your-email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

if(@mail($sendto, $subject, $mail_body, $headers)):
echo "success";
else:
echo "error";
endif;

`

davisge2
  • 1
  • 3