amrita2084 Posted April 2, 2008 Share Posted April 2, 2008 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 More sharing options...
conker87 Posted April 2, 2008 Share Posted April 2, 2008 $headers = "From: $from" . "\r\n" . 'Reply-To: [email protected]' . "\r\n"; Use quotes not apostrophes. I'll give you an example of the differences between ' and ": <?php $var = "Hello"; echo "$var there"; // Hello there echo '$var there'; // $var there ?> Link to comment https://forums.phpfreaks.com/topic/99148-php-mail-function/#findComment-507265 Share on other sites More sharing options...
amrita2084 Posted April 2, 2008 Author Share Posted April 2, 2008 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 More sharing options...
conker87 Posted April 2, 2008 Share Posted April 2, 2008 Try doing an echo $headers to see whats actually being sent. Link to comment https://forums.phpfreaks.com/topic/99148-php-mail-function/#findComment-507326 Share on other sites More sharing options...
amrita2084 Posted April 2, 2008 Author Share Posted April 2, 2008 hi its displaying like this From: [email protected] Reply-To: [email protected] Link to comment https://forums.phpfreaks.com/topic/99148-php-mail-function/#findComment-507340 Share on other sites More sharing options...
ansarka Posted April 2, 2008 Share Posted April 2, 2008 ;) <?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 More sharing options...
amrita2084 Posted April 2, 2008 Author Share Posted April 2, 2008 hi thanks for the mail method itself but stil it doesnt solve my problem...as im not able to send the mail to the person cos the FROM message fails ...pls let me know how to use headers Link to comment https://forums.phpfreaks.com/topic/99148-php-mail-function/#findComment-507366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.