homepage Welcome to WebmasterWorld Guest from 54.145.243.51
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Send mail script via SMTP
GertK



 
Msg#: 4643490 posted 1:41 pm on Feb 8, 2014 (gmt 0)

I have a form on my website where people can join events. The codes behind he for works this way:

1.
All info is saved in a database. This part work fine

2.
The second part of the codes send out an email to me and to the user with the info he intered (same info as saved in the database)

The issue is that the emails are sent unauthenticated through a default email on the hosting account. I have to modify the script to force SMTP authentication with a valid email under my hosting account to fix the error. Right now the script sends out the email but it ends in spamfilter with all ISPs so the user never receive the email.

I have no idea of how to do, or create the codes so the script use SMTP authentication. Below is the codes I have so fare. Can someone help me?

<?
// SEND OUT EMAIL PART
// COPY SEND TO MY SELF
$to = "my@email.com";
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "Thanks!";

$fields = array();
$fields{"name"} = "Name";
$fields{"address"} = "Address";
$fields{"phone"} = "Phone";
$fields{"email"} = "E-mail addesse";

$body = "INFO:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }


// SEND TO THE USER
$headers2 = "From: my@email.com";
$subject2 = "THANKS!";

$fields2 = array();
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "Thanks!";

$body2 = "

TEXT TO EMAIL RECEIVER

\n\n"; foreach ($fields2 as $a => $b){ $body2 .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

// ERROR MESSAGES
if($from == '') {print "MISSING EMAIL ADDRESS.";}
else {
if($name == '') {print "MISSING NAME";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $body2, $headers2);
if($send)
{header( "Location: http://mysite.com/send.php" );}
else
{print "MISSING EMAIL ADDRESS ALL FILDS MUST BE FILLED!"; }
}
}
?>

 

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4643490 posted 7:14 pm on Feb 11, 2014 (gmt 0)

The issue is that the emails are sent unauthenticated through a default email on the hosting account.


Actually, they are (likely) being sent via the MTA on the hosting server. Have a look at how the PHP mail() function works and you'll see what I mean.

There are many reasons that the ISP may be flagging the message as SPAM and if this is a shared hosting account you may already have an uphill battle. There may be other accounts on the server that are causing it to be marked on blacklists, etc. Google "php mail ISP spam folder" and you'll find plenty of reading and discussion.

So, you can use a third party provider for handling your mail services OR you can indeed use SMTP. If you want to examples of how to do so, just download an open source project like PHPMailer and peel it apart to see how others have opted to execute the operation.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved