dongying3830 2014-07-17 17:30
浏览 28

PHP表单:基于下拉选择的多个收件人

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('/(
+)/i',
'/(+)/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."

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

展开全部

  • 写回答

1条回答 默认 最新

  • dpl9717 2014-07-18 06:08
    关注

    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']) . "
    ";
    $headers .= "Reply-To: ". strip_tags($_POST['your-email']) . "
    ";
    $headers .= "MIME-Version: 1.0
    ";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1
    ";
    
    if(@mail($sendto, $subject, $mail_body, $headers)):
    echo "success";
    else:
    echo "error";
    endif;
    

    `

    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部