Jump to content

php mail function


amrita2084

Recommended Posts

hi every one!!

i am having problems with the mail() of php. In this,i would like to know how u can use "from header" ? for eg: im filling one form ,wich asks for UR email id and To mail id.

from this form, im retrieving the from email id , bt i cant seem to use the from email id in mail ().

i have tried " $from= $_POST['email'];

$to = $_POST['to_email'];

$body = "hi everyone";

$subject =" CHECK MAIL";

$headers = 'From: <[email protected]>' . "\r\n" . 'Reply-To: [email protected]' . "\r\n";

mail($to, $subject, $body, $headers);

 

But i would like to know how to use $from address in my mail function.

Please help me as soon as possible.

I hav tried replacing $headers =" FROM : $from ";

But it doesnt send the mail.....so i would like to know if there is any other option?plsss help

thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/99148-php-mail-function/
Share on other sites

hi thanks for immediate response...bt i tried with qoutes bt the mail is not geting send by tat.

$headers = "From: $from" . "\r\n" . 'Reply-To: [email protected]' . "\r\n";

 

any other idea...like how to send from in the php mail function...cos the above header doesnt work....pls help me

Link to comment
https://forums.phpfreaks.com/topic/99148-php-mail-function/#findComment-507315
Share on other sites

;) ;) ;)

<?php
//define the receiver of the email
$to = '[email protected]';
//define the subject of the email
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
if (DIRECTORY_SEPARATOR== '"\"')
      {
        $newLineChar = "\r\n"; //for windows
      }else
      {
        $newLineChar = "\n"; // for linux
      }
      
//define the headers we want passed. 
$headers = "From: [email protected]".$newLineChar."Reply-To: [email protected]";
//add boundary string and mime type specification
$headers .= $newLineChar."Content-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
$message ='<b> Hello sudheep ,how are you</b>';
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed";

//define the body of the message.
?>

 

Link to comment
https://forums.phpfreaks.com/topic/99148-php-mail-function/#findComment-507355
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.