i’ve got a php function which sends emails fine but I want it to use the smtp server i have specified in the ini.set function.
if i delete these 3 lines of code the email still sends fine.
the reason i want to use the smtp server is because sometimes this does not work to certain mail hosts.
connect();
$username = mysql_real_escape_string($_POST['username']);
$result = mysql_query("SELECT email FROM members WHERE username = '$_POST[username]'")
or die ("Error - Something went wrong.");
$row = mysql_fetch_array($result);
$useremail = $row['email'];
$name = "name";
$mail_from = "noreply@name.com";
$mail_to = "$useremail";
$mail_body = "Hello. Thank you for registering. Please click the link below to confirm your email address. ";
$mail_subject = "Confirm you registration".$name;
$mail_header = "From: ".$name." <".$mail_from.">\r\n";
ini_set ("SMTP", "ssl://serveraddress");
ini_set("smtp_port","465");
ini_set("sendmail_from","noreply@name.com");
$sendmail = mail($mail_to, $mail_subject, $mail_body, $mail_header);
if($sendmail == true) { mail("john@name.com", "email sent ok", "email sent to '$_POST[email]'", "yea sent ok");}
Else { mail("john@name.com", "email ERROR", "email not sent to '$_POST[email]'", "yea we got a problem");}
}
If you are serious about sending mass mailing in your web application, i’d look at the SwiftMailer library, its free and relatively easy to setup and you can set your own SMTP transporter live.
Else than that, i have had issues with sending mail to hotmail and yahoo before where the email just doesn’t get there when you use the “mail()” function. Keep in mind that the web email clients are very picky about headers, structure and security and may refuse emails not written by real clients easily.
If you want to test out something like that, just use a local-address@your-domain email, this will usually not filter it out. Now if the mail doesn’t get there, you know it’s something else.