简体   繁体   中英

PHP mailer not functioning properly

The code that I am trying to mail with is causing me problems. I want someone to be able to choose a radio button to determine whom to mail (2 choices). Currently if no radio button is chosen mail is sent to both addresses - this works. If you choose one of the buttons mail does not send to target. Below is the pertinant code.

<form action="code/submitemailCopy.php" method="post" name="submitform" id="submitform">
<p>
<label>
<input type="radio" name="toaddress" value="tim" id="tim">Tim/label>
<label>
<input type="radio" name="toaddress" value="terry" id="terry">Terry</label>


$mailto = $_POST['toaddress'];
if ($mailto == 'terry')
    $mailto = 'example1@example.com';
elseif ($mailto == 'tim')
    $mailto = 'example2@example.com';
else
    $mailto = 'example1@example.com' . ',';                 
    $mailto .= 'example2@example.com;

You need to use code blocks. Your last line is always executed, so you end up with $mailto value like example1@example.comexample2@example.com or example2@example.comexample2@example.com

if ($mailto == 'terry') {
    $mailto = 'example1@example.com';
} elseif ($mailto == 'tim')  {
    $mailto = 'example2@example.com';
} else {
    $mailto = 'example1@example.com' . ',';                 
    $mailto .= 'example2@example.com;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM