sending mail through the contact us form to the email specified in the contact form
please help me out with this problem.I have a contact form like this:
<div class="contact form">
<form action="" method="get" class="formofcontact"/>
<p>To:
<label>
<select name="select" size="1" id="select">
<option>Select</option>
<?php
$mvo=new membersVO();
$mdao=new membersDAO();
$list=$mdao->fetchAll('onlypublished');
f开发者_Go百科oreach($list as $members){?>
<option value="<?php echo "$members->email1" . "," . "$members->email2" . "," . "$members->email3";?>"><?php echo $members->name;?></option>
<?php
}
?>
</select>
</label></p>
<p>From:
<label>
<input type="text" name="textfield2" id="textfield2" /> </label>
</p>
<p>Subject:
<label>
<input type="text" name="textfield3" id="textfield3" />
</label>
</p>
<p>Message:</p>
<p>
<label>
<textarea name="textarea" id="textarea" cols="45" rows="5"> </textarea> </label>
</p>
<p>
<label>
<input type="submit" name="button" id="button" value="Send" />
</label>
</p>
</form>
Now if someone wants to send email to australian representative then they select australia and they write thir email in the from textbox.Now what i am confused is to send the email in the respective email addresses selected by the viewers.
Please guys help me out.
PHP's mail function
Just be sure to validate the input. Make sure that your form can't be used to send spam.
Here are a few points
1- Use method="POST"
instead of GET in your <form>
for sending large data like an email.
2- Do not put actual email addresses inside <option>
's value that will reveal those emails to SPAM email crawlers, just put member's id or the name itself in there:
foreach($list as $member) {
echo '<option value="'.$member->id.'">'.$member->name.'</option>';
}
then when you receive the data find that member and get its email:
$selectedMember = null;
foreach($list as $member) {
if( $member->id == $_POST['select'] ) {
$selectedMember = $member;
}
}
if( $selectedMember === null ) die( 'invalid member' );
and to send the email:
if(!@mail($selectedMember->email1, $subject, $body,
"Return-Path: <$replyEmail>\nFrom: $name <$replyEmail>") )
{
echo 'error';
} else {
echo 'message sent successfully';
}
精彩评论