Jump to content

PHP Mail (Localhost)


tebrown

Recommended Posts

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 8)

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

?>

 

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.