Jump to content

PHP Mail (Localhost)


tebrown

Recommended Posts

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

?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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


?>

 

Link to comment
Share on other sites

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

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.