drop down menu for the to: variable

the mail() function

Moderators: egami, macek, gesf

Post Reply
User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Tue Jul 08, 2003 11:54 am

for your menu box, you could use:

<select name="to">
<option value="sales@domain.com">sales</option>
<option value="parts@domain.com">parts</option>
</select>

and then just use $to in your to: field.

Andrew

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Tue Jul 08, 2003 10:30 pm

For the mail function, the to should be just an email address.

So mail("To: $toaddress") would be sending an email to "To: $toaddress". You should not have the to.

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Tue Jul 08, 2003 11:48 pm

yeah that too, see http://www.php.net/mail for details on this function :)

Andrew

pazzoboy
New php-forum User
New php-forum User
Posts: 10
Joined: Wed Dec 03, 2003 5:23 pm
Location: Rochester
Contact:

Tue Jan 27, 2004 7:37 pm

I'll modify your code a bit for you. Couple of things: "name" might be a problem, as I think it might be reserved, so I changed it to customerName. $recipient and those other ones were not even used in the php script, as you got everything you need from the $_POST[ ] variable assignments. Then, $sales, $parts, etc., were not necessary, as all you need is one variable ($contact) to catch the results of the user's selection. You should put those values (the email addresses) in the html form.

<?php
//One variable to declare here
$subject = "Contact Form submission";

//Contents of form
$contact = $_POST['contact'];
$customerName =$_POST['customerName'];
$email =$_POST['email'];
$phone =$_POST['phone'];
$comments =$_POST['comments'];
//mail() function sends the mail
mail($contact,$subject,"Name: " . $name. "\r\nPhone: ".$phone . "\r\nQuestion: ". $comments,"From: $email");
?>

<form action=contactform.php method=post>
<table width="90%" border="0" align="center">
<tr>
<td width="19%">Contact: </td>
<td width="81%">
<select name="contact">
<option value="sales@myserver.com">sales</option>
<option value="parts@myserver.com">parts</option>
<option value="service@myserver.com">Service Department</option>
<option value="website@myserver.com">Website Design</option>
</select>
</td>
</tr>
<tr>
<td width="19%" height="19">Name: </td>
<td width="81%" height="19">
<input type="text" name="customerName">
</td>
</tr>
<tr>
<td width="19%">Email:</td>
<td width="81%">
<input type="text" name="email">
</td>
</tr>
<tr>
<td width="19%">Phone:</td>
<td width="81%">
<input type="text" name="phone" value="( )">
</td>
</tr>
<tr>
<td width="19%">Message:</td>
<td width="81%">
<textarea name="comments" rows="3"></textarea>
</td>
</tr>
<tr>
<td width="19%">&</td>
<td width="81%">
<input type="submit" name="Submit" value="Send">
</td>
</tr>
</table>
</form>
I'm not crazy, just pazzo

Martin Pickering
New php-forum User
New php-forum User
Posts: 106
Joined: Fri Oct 17, 2003 8:00 am

Mon Apr 19, 2004 2:25 pm

Just an observation, based on experience!

If you put email addresses into a form, they will be spammed.

Better to put
<option value="sales">sales</option>
<option value="parts">parts</option>
<option value="service">Service Department</option>
<option value="website">Website Design</option>

Then add "@myserver.com" to the contact name in the PHP script.

But get it working first before bothering with this!

Martin Pickering (UK)

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests