darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 i edited for you check above Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1375977 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 Hmm, yeah its still sending to junk. This is really annoying aye. Also why does it show the content within the actual message? <? $subject = mysql_real_escape_string($_POST["subject"]); $body = mysql_real_escape_string($_POST["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: \"".$name."\" <".$to.">".PHP_EOL; $headers .= "From: ".$from." <".$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 mail($to, $subject, $body, $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1375978 Share on other sites More sharing options...
trq Posted September 7, 2012 Share Posted September 7, 2012 There is no such ini directive as username & password. I'm not sure where darkfreaks got the idea, but it is wrong. PHP's mail function does not support authentication. If your using an external mail server or your mail server requires authentication to be accessed, you will be best off using a third party library like PHPMailer or SwiftMailer of similar. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1375982 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 If i was not to use PHP mailer, would you know whats wrong with the above code in regards to why its sending to junk mail? was not* Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1375984 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 @ thorpe it is a hack at best i saw floating around. i am still lost why the OP needs SMTP for junk filters? he needs to switch to Phpmailer if he wants to use SMTP. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1375993 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 If i send to gmail, it goes to inbox, i think its just Hotmail that marks it as spam/junk? Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1375995 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 //microsoft x-mail headers $headers .= "X-MSMail-Priority: High\n"; $headers .= "Importance: High\n"; please lord let this work so i can go to bed at 5am *prays* Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1375996 Share on other sites More sharing options...
tebrown Posted September 7, 2012 Author Share Posted September 7, 2012 Still goes to junk... $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: \"".$name."\" <".$to.">".PHP_EOL; $headers .= "From: ".$from." <".$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; $headers .= "X-MSMail-Priority: High\n"; $headers .= "Importance: High\n"; Mate, you can go to bed, don't want to keep you up. I can wait for a response. Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1375998 Share on other sites More sharing options...
darkfreaks Posted September 7, 2012 Share Posted September 7, 2012 i think i left out the priority only put the importance. //set xmail priority $headers .= "X-Priority: 1 (Highest)".PHP_EOL; //set microsoft mail priority $headers .= "X-MSMail-Priority: High".PHP_EOL; //set to high $headers .= "Importance: High".PHP_EOL; Documentation Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1376001 Share on other sites More sharing options...
darkfreaks Posted September 8, 2012 Share Posted September 8, 2012 Shortcomings of mail The mail function has many limitations. [*]no SMTP Support [*]Difficult to format headers(but can be done) [*]difficult to add attachments(but can be done) Changed code to use phpmailer with MSheaders: <?php require('class.phpmailer.php'); $subject = mysql_real_escape_string($_POST["subject"]); $body = mysql_real_escape_string($_POST["message"]); $host="smtp@example.com"; $to = "t.e.brown@hotmail.com"; $name = "".$_SESSION['name'].""; $from = "".$_SESSION['email'].""; $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->Host = $host; //SMTP server $mail->From = $from; $mail->FromName = $name $mail->AddAddress($to); $mail->AddReplyTo($from); $mail->Subject = $subject; $mail->Body = $body; //make sure it does not get sent as html message// $mail->ContentType = 'text/plain'; $mail->IsHTML(false); $mail->WordWrap = 50; // set word wrap //set xmailer priority// $mail->Priority =1; // MS Outlook & hotmail header may also use "Urgent" or "highest" // $mail->AddCustomHeader("X-MSMail-Priority: High"); $mail->AddCustomHeader("Importance : High"); if($mail->Send()) { echo "Message Sent"; } else { echo "Message Not Sent<br>"; echo "Mailer Error: " . $mail->ErrorInfo; } ?> note: mail clients are free to not implement/ignore these headers, so you can't fully rely on them. Also, many spam filters will use them as a red flag for identifying spam. Use them with caution. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1376255 Share on other sites More sharing options...
PFMaBiSmAd Posted September 8, 2012 Share Posted September 8, 2012 The email is not being sent FROM the name/email you have in $_SESSION['name'] and $_SESSION['email']. It is being sent FROM your mail server to a hotmail mail server. The domain name you put in the email address in the FROM header must match the domain at the sending mail server or you must have an SPF DNS record at the domain being put into the FROM address that indicates the sending mail server is authorized to send email for that domain. Also, read the following - http://mail.live.com/mail/troubleshooting.aspx Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1376257 Share on other sites More sharing options...
darkfreaks Posted September 8, 2012 Share Posted September 8, 2012 tweaked the code abit to allow for username and password for smtp auth as well as the number of the port in this case 25 or 26. also changed $_SESSION to $_REQUEST i have a feeling $_SESSION is not matching or being sent one of the two. that and the fact i can not find one example of using sessions in phpmailer. <?php require('class.phpmailer.php'); $subject = mysql_real_escape_string($_POST["subject"]); $body = mysql_real_escape_string($_POST["message"]); $to = "t.e.brown@hotmail.com"; $name = "".$_REQUEST['name'].""; $from = "".$_REQUEST['email'].""; $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->Host ="smtp.example.com";//smtp host $mail->Username = "mail@domain.com"; //smtp username $mail->Password = "password"; //smtp password $mail->Port = "26";//smtp port $mail->SMTPAuth =true; // turn on smtp auth $mail->From = $from; $mail->FromName = $name $mail->AddAddress($to); $mail->AddReplyTo($from); $mail->Subject = $subject; $mail->Body = $body; //make sure it does not get sent as html message// $mail->ContentType = 'text/plain'; $mail->IsHTML(false); $mail->WordWrap = 50; // set word wrap //set xmailer priority// $mail->Priority =1; // MS Outlook & hotmail header may also use "Urgent" or "highest" // $mail->AddCustomHeader("X-MSMail-Priority: High"); $mail->AddCustomHeader("Importance : High"); if($mail->Send()) { echo "Message Sent"; } else { echo "Message Not Sent<br>"; echo "Mailer Error: " . $mail->ErrorInfo; } $mail->ClearAdresses(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1376258 Share on other sites More sharing options...
darkfreaks Posted September 8, 2012 Share Posted September 8, 2012 but if i read the above right he should use whatever email his hosting provides him instead of a gmail or hotmail account. is the main problem i see. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1376262 Share on other sites More sharing options...
Stefany93 Posted September 8, 2012 Share Posted September 8, 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. It is not a good idea to send emails from localhost because by default your ISP will try to limit or not allow you at all to send emails since the ISPs do not want the people they give Internet to spam other people's mail boxes because that way it will be very easy. Write your code and then upload it to a server with PHP MAIL() function enabled and you will be fine. Yeah the testing will be a bit difficult, but it is worth it :-) Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1376271 Share on other sites More sharing options...
darkfreaks Posted September 8, 2012 Share Posted September 8, 2012 Using localhost with phpmailer pretty much the same code i provided only $host is set to localhost & smtpauth has been turned off. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1376273 Share on other sites More sharing options...
trq Posted September 8, 2012 Share Posted September 8, 2012 @ thorpe it is a hack at best i saw floating around. It does nothing. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1376276 Share on other sites More sharing options...
darkfreaks Posted September 9, 2012 Share Posted September 9, 2012 anyhow OP contacted me this is solved now or should be marked as such. Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1376410 Share on other sites More sharing options...
premiso Posted September 9, 2012 Share Posted September 9, 2012 anyhow OP contacted me this is solved now Would you mind posting the solution (if possible) here so that others may benefit? Quote Link to comment https://forums.phpfreaks.com/topic/268103-php-mail-localhost/page/2/#findComment-1376462 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.