Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

PHP Email Script

the mail() function

Moderators: macek, egami, gesf

PHP Email Script

Postby bbcompent1 » Fri Oct 21, 2011 3:17 am

Hello everyone, I'm curious about something. I have a PHP Email script that I'm trying to get working and I think the code is right but just need a second pair of eyes to check it. It seems something in my if elseif else structure is hosed. The site does indeed email properly because I have each request followed by an autoresponder to the message sender. This is the block I'm stuck on:

Code: Select all
if ($to=="sales@mydomain.com")
$subject="RFQ"
mail("1112223333@messaging.sprintpcs.com","","noreply@mydomain.com","You have received a site RFQ request.")
elseif ($to==webmaster@mydomain.com)
$subject="Website Related";
mail("1112223333@messaging.sprintpcs.com","","noreply@mydomain.com","You have received a site website request.")
elseif ($to==support@mydomain.com)
mail("1112223333@messaging.sprintpcs.com","","noreply@mydomain.com","You have received a site support request.")
$subject="Account support request";
else
$subject="Contact Request";
mail("5857090023@messaging.sprintpcs.com","","noreply@mydomain.com","You have received a site contact request.")
bbcompent1
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Oct 21, 2011 3:11 am

Re: PHP Email Script

Postby egami » 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: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: PHP Email Script

Postby egami » 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.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: PHP Email Script

Postby bbcompent1 » Fri Oct 21, 2011 4:46 am

That does look a lot cleaner. I'll give that a try and get back to you. Thanks! :)
bbcompent1
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Oct 21, 2011 3:11 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.