tebrown Posted September 7, 2012 Share Posted September 7, 2012 Hey Guys, Did some search around these forums, but couldn't find any appropriate topics regarding this that will solve my problem. Anyway, i have set up php mail on my localhost but the messages that i send still get sent to my junk/spam. $subject = mysql_real_escape_string($_REQUEST["subject"]); $body = mysql_real_escape_string($_REQUEST["message"]); $to = "t.e.brown@hotmail.com"; $name = "".$_SESSION['name'].""; $from = "".$_SESSION['email'].""; $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/plain; charset=utf-8\n"; $headers .= "To: ".$to."\n"; $headers .= "From: ".$name." <".$from.">\n"; $headers .= "Reply-To: ".$name." <".$from.">\n"; $headers .= "Return-Path: ".$from." <".$from.">\n"; $headers .= "X-Mailer: PHP's mail() Function\n"; $headers .= "\n"; mail($to, $subject, $body, $headers); Would anyone be able to help me out here and look over the code. Any tips to make this better so that it doesn't go to my junk mail? Thanks for your help, much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/ Share on other sites More sharing options...
trq Posted September 7, 2012 Share Posted September 7, 2012 Do you have a proper domain setup to send mail from? Hotmail will likely see mail coming from anything but a proper domain as spam. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375940 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 What does localhost (MAMP) currently use? I also have a web hosting server that contains a mail domain? - how do i implement into the above code? Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375942 Share on other sites More sharing options...
trq Posted September 7, 2012 Share Posted September 7, 2012 Unless you have a domain resolving to your local network you don't have one. I also have a web hosting server that contains a mail domain? - how do i implement into the above code? you would need to send the mail from that server. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375944 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 also make sure you have the proper headers so they are less "spammy" and liable to end up in the junk folder. i had this problem awhile back and i ended up using PHP_EOL as a linebreak character and it solved my linebreak problem and my attachment images being corrupt. $headers = "MIME-Version: 1.0".PHP_EOL; $headers .= "Content-type: text/plain; charset=utf-8".PHP_EOL; $headers .= "To: ".$to."".PHP_EOL; $headers .= "From: ".$name." <".$from.">".PHP_EOL; $headers .= "Reply-To: ".$name." <".$from.">".PHP_EOL; $headers .= "Return-Path: ".$from." <".$from.">".PHP_EOL; $headers .= "X-Priority: 3".PHP_EOL; $headers .= "X-Mailer: PHP". phpversion() ."".PHP_EOL; Also as Thorpe suggested you might want to make sure your domain is not being marked as spam. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375945 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 What would i need to implement into that php for it to access the web server? Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375946 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 Also as Thorpe suggested you might want to make sure your domain is not being marked as spam. Is there a way to do that on your web hosting mail server? Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375948 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 Check if your email server is blacklisted as spam Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375949 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 What would be needed to connect to the SMTP server within my php code? Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375953 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 //specify your SMTP domain ini_set ( "SMTP", "smtp-server.example.com" ); // Please specify an SMTP Number 25 and 8889 are valid SMTP Ports. ini_set("smtp_port","25"); Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375955 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 Will thi require password and username to access my mail server? Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375957 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 you can also set the username and pass using ini_set //if password auth is required ini_set("username" , "myusername"); ini_set("password", "mypassword"); Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375958 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 Ok so it would end up looking something like this? //specify your SMTP domain ini_set ( "SMTP", "smtp-server.example.com" ); // Please specify an SMTP Number 25 and 8889 are valid SMTP Ports. ini_set("smtp_port","25"); //if password auth is required ini_set("username" , "myusername"); ini_set("password", "mypassword"); $subject = mysql_real_escape_string($_REQUEST["subject"]); $body = mysql_real_escape_string($_REQUEST["message"]); $to = "t.e.brown@hotmail.com"; $name = "".$_SESSION['name'].""; $from = "".$_SESSION['email'].""; $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/plain; charset=utf-8\n"; $headers .= "To: ".$to."\n"; $headers .= "From: ".$name." <".$from.">\n"; $headers .= "Reply-To: ".$name." <".$from.">\n"; $headers .= "Return-Path: ".$from." <".$from.">\n"; $headers .= "X-Mailer: PHP's mail() Function\n"; $headers .= "\n"; mail($to, $subject, $body, $headers); Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375959 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 yes correct but on your actual server replace "mypassword" and "myuser" with the actual details and the actual server as well. also it would not be a bad idea to update the headers like i showed you. above. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375960 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 Ok i will try this now and get back to you. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375961 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 Ok i made the changes, even the headers. It still goes to junk email in hotmail. How do you know if your actually connect to your mail server? Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375964 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 can i see the code please Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375965 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 No worries, here it is. I've replaced my site name with domain. Has not been released yet that is all. $subject = mysql_real_escape_string($_REQUEST["subject"]); $body = mysql_real_escape_string($_REQUEST["message"]); //specify your SMTP domain ini_set ( "SMTP", "mail.domain.co.nz" ); // Please specify an SMTP Number 25 and 8889 are valid SMTP Ports. ini_set("smtp_port","25"); //if password auth is required ini_set("username" , "info@domain.co.nz"); ini_set("password", "********"); $subject = mysql_real_escape_string($_REQUEST["subject"]); $body = mysql_real_escape_string($_REQUEST["message"]); $to = "t.e.brown@hotmail.com"; $name = "".$_SESSION['name'].""; $from = "".$_SESSION['email'].""; $headers = "MIME-Version: 1.0".PHP_EOL; $headers .= "Content-type: text/plain; charset=utf-8".PHP_EOL; $headers .= "To: ".$to."".PHP_EOL; $headers .= "From: ".$name." <".$from.">".PHP_EOL; $headers .= "Reply-To: ".$name." <".$from.">".PHP_EOL; $headers .= "Return-Path: ".$from." <".$from.">".PHP_EOL; $headers .= "X-Priority: 3".PHP_EOL; $headers .= "X-Mailer: PHP". phpversion() ."".PHP_EOL; mail($to, $subject, $body, $headers); Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375966 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 I just looked at my settings in my web hosting. This is what it says. Mail Server Username: info+rugbymanager.co.nz Incoming Mail Server: mail.rugbymanager.co.nz Incoming Mail Server: (SSL) mail.emailserver.co.nz Outgoing Mail Server: mail.rugbymanager.co.nz (server requires authentication) port 26 Outgoing Mail Server: (SSL) mail.emailserver.co.nz (server requires authentication) port 465 Supported Incoming Mail Protocols: POP3, POP3S (SSL/TLS), IMAP, IMAPS (SSL/TLS) Supported Outgoing Mail Protocols: SMTP, SMTPS (SSL/TLS) Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375967 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 need outgoing mail and need to change the port from 25 to 26. i really don't see why you need smtp though.i am pretty sure the junk issue is a header issue. <?php $subject = mysql_real_escape_string($_REQUEST["subject"]); $body = mysql_real_escape_string($_REQUEST["message"]); //specify your SMTP domain ini_set ( "SMTP", "mail.domain.co.nz" ); // Please specify an SMTP Number 25 and 8889 are valid SMTP Ports. ini_set("smtp_port","25"); //if password auth is required ini_set("username" , "info@domain.co.nz"); ini_set("password", "********"); $subject = mysql_real_escape_string($_REQUEST["subject"]); $body = mysql_real_escape_string($_REQUEST["message"]); $to = "t.e.brown@hotmail.com"; $uid= md5(uniqid(time())); $name = "".$_SESSION['name'].""; $from = "".$_SESSION['email'].""; $headers = "MIME-Version: 1.0".PHP_EOL; $headers .= "--PHP-mixed-".$uid."".PHP_EOL; $headers .= "Content-Type: multipart/alternative; boundary=\"PHP-alt-".$uid."\"".PHP_EOL; $headers .= "--PHP-alt-".$uid."".PHP_EOL; $headers .= "Content-type: text/html; charset=utf-8".PHP_EOL.PHP_EOL; $headers .= "Content-Transfer-Encoding: 7bit".PHP_EOL; $headers .= "To: ".$to."".PHP_EOL; $headers .= "From: ".$name." <".$from.">".PHP_EOL; $headers .= "Reply-To: ".$name." <".$from.">".PHP_EOL; $headers .= "Return-Path: ".$from." <".$from.">".PHP_EOL; $headers .= "X-Priority: 3".PHP_EOL; $headers .= "X-Mailer: PHP". phpversion() ."".PHP_EOL; //message headers $body .= "Content-type: text/plain; charset=utf-8".PHP_EOL.PHP_EOL; mail($to, $subject, $body, $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375969 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 Yeah its good practice though! - i tired the headers without SMTP - it still goes to junk? Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375971 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 here is a few examples to show you where i am going with this Example 1 example 2 you are telling me without the smtp stuff you are still getting it in junk mail? because when i used these tutorials to fix my mail image attachment it sent fine to gmail|hotmail and mozilla thunderbird & microsoft outlook. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375972 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 Yes it was still not working even without the SMTP info. I'll look at those examples now. Here is a screenshot of what its like in my hotmail: Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375973 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 check if your message and title has been set empty titles or messages are usually sent to junk. but for perks here is an updated to line for the headers $headers .= "To: \"".$name."\" <".$to.">".PHP_EOL; also i would use #$_POST instead of $_REQUEST especially if you are checking for empty or isset Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375975 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 So i should replace that with the original 'To:'? - and then create 2 new variables ($to_name, $to_email)? Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/#findComment-1375976 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.