0

i read a lot regarding this issue, and didn't really get clear answer

i simply have local server at home which has xampp and sendmail is working fine... i am using the sendmail folder that comes with xampp and all is fine

  • i have uncommented the sendmail path address... and put my localhost smtp information, user/pass all ok... works fine
  • there is another option to

force_sender=test@domain.com

when using this, it sends the email ok, i get in my normal email clinet an email from address: test@domain.com... that is fine

problem is i really want to define the sender name, like comes from MAIL SENDER

something like FROM: "John "

tried with quotes in the force_sender place, no change... i have this mailbox exisited in my xampp (hmail server) and i put the settings there to use FIRST NAME and LAST name like John Smith, but didn't work... all the time just coming like from address format: test@domain.com

this is also similar, but nobody really could help me to clear this doubt and get rest - yet

From address is not working for PHP mail headers

Community
  • 1
  • 1
MikeDerik
  • 37
  • 10

2 Answers2

0

if you want to set sender name than you have to set into in headers. try this

$senderName="John";
$senderEmail= "test@domain.com";
$recipient = "recipient@domain.com";
$subject ="testmail";
$message="test message";


$headers = "From: " . $senderName . " <" . $senderEmail . ">";

$success = mail($recipient, $subject, $message, $headers );
Lokesh Jain
  • 579
  • 6
  • 19
  • no dear, that is if you want to send an email, this is sendmail folder (the fake mail sender) that comes with xampp, i can't put those variables in the sendmail.ini file, there is only like mentioned above force_sender and smtp settings – MikeDerik Sep 11 '14 at 14:51
  • come one guys, experts... anybody? – MikeDerik Sep 11 '14 at 21:52
0

A better approach in php is to use the library phpmailer.

Sending an e-mail would look like this and you can set any fields you want (off course you don't always need that many as in the example). I guess $mail->FromName = "Your name"; is what you're looking for.

<?php

require '/whereeveritis/PHPMailerAutoload.php';
$mail = new PHPMailer;

//Enable SMTP debugging. 
$mail->SMTPDebug = 3;                               
//Set PHPMailer to use SMTP.
$mail->isSMTP();            
//Set SMTP host name                          
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;                          
//Provide username and password     
$mail->Username = "youraddress@gmail.com";                 
$mail->Password = "yourpasswordinplaintextyeah";                           
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";                           
//Set TCP port to connect to 
$mail->Port = 587;                                   

$mail->From = "name@gmail.com";
$mail->FromName = "Your name";

$mail->addAddress("name@example.com", "Recepient Name");

$mail->isHTML(true);

$mail->Subject = "Whatever good subject you like to use";
$mail->Body = "Mail body in HTML";
$mail->AltBody = "plain text version";

if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}
Keun
  • 1