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

 

Link to comment
Share on other sites

$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

?>

Link to comment
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: 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

Link to comment
Share on other sites

;) ;) ;)

<?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.
?>

 

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.