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: <register@tech.com>' . "\r\n" . 'Reply-To: register@tech.com' . "\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 Quote Link to comment Share on other sites More sharing options...
conker87 Posted April 2, 2008 Share Posted April 2, 2008 $headers = "From: $from" . "\r\n" . 'Reply-To: register@tech.com' . "\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 ?> Quote Link to comment 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: register@tech.com' . "\r\n"; any other idea...like how to send from in the php mail function...cos the above header doesnt work....pls help me Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
amrita2084 Posted April 2, 2008 Author Share Posted April 2, 2008 hi its displaying like this From: amrita_84@google.com Reply-To: webmaster@qaguild.com Quote Link to comment 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 = 'youraddress@example.com'; //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: webmaster@example.com".$newLineChar."Reply-To: webmaster@example.com"; //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. ?> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.