0

我需要一个表单来根据用户下拉选择发送给多个不同的收件人。这是我到目前为止所阅读的内容......我可以让它说成功,但我没有收到电子邮件。请帮忙!!

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;
?>

我需要它是标头注入安全的。

4

1 回答 1

0

我刚变

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

对此

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

并将邮件部分发送到此:

`

$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;

`

于 2014-07-18T14:08:16.417 回答