PHP Email Script

the mail() function

Moderators: egami, macek, gesf

Post Reply
User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Fri Oct 21, 2011 4:35 am

is $to defined?
If it's a string, it needs to be encapsulated in quotes..

if ($to == "somewhere@somedomain.com") {
do this..
} elseif ($to == "elsewhere@someotherdomain.com") {
do that...
}

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Fri Oct 21, 2011 4:42 am

But I wouldn't have those emails as drop downs in your form as far as values go.

I would do it a little like this.

Code: Select all

..other form stuff ehre...
<select name="tofield">
  <option value="1">Contact Request</option>
  <option value="2">Price Check on Isle 3</option>
  <option value="3">Can I speak to a Manager</option>
</select>
</form>
And then on your mailing side..

Code: Select all

$array = array('1'=>'contact@mydomain.com',
                    '2'=>'pricecheck@mydomain.com',
                    '3'=>'manager@mydomain.com');

if (isset($_POST['tofield'])) { 
  $to = $_POST['tofield'];
} else { 
  $to = 'default';
}

switch ($to) { 
  case 1:
    $subject = "Contact Request Information";
    $mailto = $array['1'];
    break;

  case 2:
    $subject = "Price Check on Isle 3";
    $mailto  = $array['2'];
    break;

  case 3:
    $subject = "I need to speak to your Manager";
    $mailto = $array['3'];
    break;

  default:
    $subject = "Customer didn't pick an option, so this is the catch all.";
    $mailto = "mydefaultmailbox@mydomain.com";
    break;
}

 
switch is WAY faster than IF.
having an array stuffed on the backside prevents HTML EMAIL scrubbing.
Having a catch all will help catch the customer that doesn't understand left mouse click.


Good luck.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest