0

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");}

}
  • What errors do you get? You are aware that SMTP sending is limited to Windows servers? – Pekka Oct 01 '11 at 11:25
  • thats the strange thing. i get no errors. it sends fine to gmail but to hotmail just does not appear. (its not in junk or spam anywhere) And i never knew smtp sending was limited to windows servers. Is this way ok to do it on a linux server? – lennard2011 Oct 01 '11 at 11:26
  • "it's my code, fix it" questions are not allowed. – OZ_ Oct 01 '11 at 11:38
  • @OZ_ its not a "it's my code, fit it" question. im trying to find out why its not using the ini.set function. – lennard2011 Oct 01 '11 at 11:41

1 Answers1

1

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.

Mathieu Dumoulin
  • 11,584
  • 6
  • 38
  • 65
  • Ok so if i change the headers and setup a hotmail and yahoo account and make sure it gets to both of them i should be fine? Its not really mass email its more around 20 emails a day or so. Hopefully increasing as time goes on. – lennard2011 Oct 01 '11 at 11:33
  • Yeah, work with the headers and the content structure. Note that if you send 20 emails or 200 emails or 2000 emails, it is a massmail. If you send a message to someone like an admin stating there is a new order placed on his site, now that is a single target email :) – Mathieu Dumoulin Oct 01 '11 at 11:41
  • ok thanks for the help. ill have a look at swiftmailer. seems like it can use the built in PHP mail function :) – lennard2011 Oct 01 '11 at 11:43