1. Welcomecaller.php
<form name="myForm"
action="/send.php" method="post">
<input type="hidden" name="subject" value="Form Submission" />
<input type="hidden" name="redirect" value="thankyou.html" />
Name: <input type="text" name="fname" />
Email: <input type="text" name="email" />
Phone No: <input type="text" name="phone" />
<input type="submit" name="submit" value="submit"/>
</form>
2. Send.php
<?php
$to = "safiullah12@hotmail.com";
$subject = "Brought to you ";
$Sender = "info@bengalilist.com";

$message = $_POST["fname"] . "\r\n".
$_POST["email"] . "\r\n".
$_POST["phone"] . "\r\n" ;
// Echo "Name: $FirstNam . \tEmail Address: $Email " ;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

$headers = "From: ".$Sender . "\r\n" .
'Reply-To: '.$Sender. "\r\n".
'X-Mailer: PHP/' . phpversion();

if (mail($to,$subject,$message, $header)){
echo("<p>Message successfully sent!</p>");
echo ( '<A href = "index.php">Home Page</A>' );
} else {
echo("<p>Message delivery failed...</p>");
}

?>
3. User enter in number 1(welcomecaller.php) as below: john for Name. abc@hotmail.com for email. 6092141834 for phone.
4. I get email no problem. I get email as below:
john
abc@hotmail.com
6092141834

5. Instead, I am expecting an output as below. How can I get an output as below?

Name = john
Email = abc@hotmail.com
Phone = 6092141834


Someone pls correct my code and help me getting an output as no-5.

Thanks a lot.

<?php 
$to = "safiullah12@hotmail.com";
$subject = "Brought to you ";
$Sender = "info@bengalilist.com";

$name = $_POST["fname"];
$email = $_POST["email"];
$phone = $_POST["phone"];

$message = "\nName = $name\nEmail = $email\nPhone = $phone";
// Echo "Name: $FirstNam . \tEmail Address: $Email " ;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

$headers = "From: ".$Sender . "\r\n" .
'Reply-To: '.$Sender. "\r\n".
'X-Mailer: PHP/' . phpversion();

if (mail($to,$subject,$message, $header)){
echo("<p>Message successfully sent!</p>");
echo ( '<A href = "index.php">Home Page</A>' );
} else {
echo("<p>Message delivery failed...</p>");
}

?>

thanks.

but i get this error, when i run it, : mail() [function.mail]: SMTP server response: 451 .... line 24

line 24.......if (mail($to,$subject,$message, $header)){

Oops, it is because your host is probably using Qmail which requires "\r\n" instead of just "\n". Try this code and see if it works.

<?php 
$to = "safiullah12@hotmail.com";
$subject = "Brought to you ";
$Sender = "info@bengalilist.com";

$name = $_POST["fname"];
$email = $_POST["email"];
$phone = $_POST["phone"];

$message = "\r\nName = $name\r\nEmail = $email\r\nPhone = $phone";
// Echo "Name: $FirstNam . \tEmail Address: $Email " ;

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

$headers = "From: ".$Sender . "\r\n" .
'Reply-To: '.$Sender. "\r\n".
'X-Mailer: PHP/' . phpversion();

if (mail($to,$subject,$message, $header)){
echo("<p>Message successfully sent!</p>");
echo ( '<A href = "index.php">Home Page</A>' );
} else {
echo("<p>Message delivery failed...</p>");
}

?>

You are great.
i get result as below:
Name = new line test
Email = new line test
Phone = 123 456 7890

1)another problem with the code is that i receive email in junk folder. but if i change $to to work email then i get an email to inbox folder. i explained that to hosting provider, they said bc of public email. they said if u need to use public email, u need to find workaround to get the public email in inbox folder. i am not sure how can i do that?
--------------------
2)another big big favour. question, i want to receive an email from the user instead of domain name email.

above code shows sender is a webmaster.

below code -line 4 is different than original code. after i run below code, receiver($To)also sees sender is a webmaster.

<?php
$to = "safiullah12@hotmail.com";
$subject = "Brought to you by BengaliList.com";
$Sender = $_POST["email"];

$EmailAd = "Email Address";
$Namee = "Name";
$Phon = "Phone";

$name = $_POST["fname"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$message = "\r\nName = $name\r\nEmail = $email\r\nPhone = $phone";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

$headers = "From: ".$Sender . "\r\n" .
'Reply-To: '.$Sender. "\r\n".
'X-Mailer: PHP/' . phpversion();

if (mail($to,$subject,$message, $header)){
echo("<p>Message successfully sent!</p>");
echo ( '<A href = "index.php">Home Page</A>' );
} else {
echo("<p>Message delivery failed...</p>");
}

?>
when A enters email address($sender) and hit submit, once B($To)receive the msg in inbox folder, B needs to reply to A by clicking reply. Thats why i need to implement into my code.

Pls help!thx

Hi,

Both problems you have now are not a problem with the code but rather a typical problem with email in general. Basically it comes down to configuration of email server etc.

For the first question, the email you get in Hotmail is going your junk folder? That would be a configuration of Hotmail and what it considers to be junk mail. It may be going in there because the host address has been put into a email spam blacklist somewhere possibly. Just going into your junk mail folder and telling Hotmail that it is not junk email should resolve that. Basically the sender of the email needs to be an email that is part of the hosting domain.

For the second question, the code can be setup to put in the senders email as the from address but you will most likely not even get the email because the mail will most likely fail to be sent from the server. This is because it would be considered an relaying and almost every "smart" administrator configures the mail server to not be an open relay and only send email from the domain that it is being sent from. A better solution though would be to set the 'reply to' address as the users email then when someone clicks reply it will send the email to that user rather than the webmaster email you had gotten the email from originally. The reason you don't want the mail server to send mail as any other domain then the one hosted on it is because I can hit the mail server with telnet and send out emails all day from your server and then it will get blacklisted and put on spam lists and then lots of people will not get your emails anymore.

<?php 
$to = "safiullah12@hotmail.com"; // it is best to have the email sent to a email that is part of the domain.
$subject = "Brought to you by BengaliList.com";
$Sender = "someone@somedomain.com"; // set this to an email address on the domain where the email is coming from.

$EmailAd = "Email Address";
$Namee = "Name";
$Phon = "Phone";

$name = $_POST["fname"];
$email = $_POST["email"];
$phone = $_POST["phone"]; 
$message = "\r\nName = $name\r\nEmail = $email\r\nPhone = $phone";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

$headers = "From: ".$Sender . "\r\n" .
'Reply-To: '.$email. "\r\n". // set the reply-to to the address from the email form so when someone hits reply it goes to this address.
'X-Mailer: PHP/' . phpversion();

if (mail($to,$subject,$message, $header)){
echo("<p>Message successfully sent!</p>");
echo ( '<A href = "index.php">Home Page</A>' );
} else {
echo("<p>Message delivery failed...</p>");
}

?>

Many many thanks for your time.

Hotmail >I still receive the email in junk folder/hotmail. When it goes to junk folder, there is no reply button in hotmail. Then I move the email from junk to inbox folder. I click reply but I don’t see user email in TO field. Instead,I see webmaster email address in TO field. Also, in the body of email, users email address is not linked?

Gmail> then I change $To to gmail address. I get email at gmail inbox folder. Good news. But when I click reply, I only see “webmaster email address” in TO field. How can I have user’s email address in TO field instead. in the body of email, users email address is linked unlike hotmail.

pls help.

Well, not a lot you probably can do about Hotmail. I sort of hate Hotmail lol and always use gmail.

As for the reply-to, I have fixed that. In fact the variable in your mail() for $headers was wrong and just said $header which means none of those were getting sent. Also, the additional headers you had set I removed. I really don't think they are necessary and the mail server usually takes care of that when sending the email.

<?php 
$to = "safiullah12@hotmail.com"; // it is best to have the email sent to a email that is part of the domain.
$subject = "Brought to you by BengaliList.com";
$Sender = "someone@somedomain.com"; // set this to an email address on the domain where the email is coming from.

$EmailAd = "Email Address";
$Namee = "Name";
$Phon = "Phone";

$name = $_POST["fname"];
$email = $_POST["email"];
$phone = $_POST["phone"]; 
$message = "\r\n Name = $name\r\n Email = $email\r\n Phone = $phone";

// Always set content-type when sending HTML email
$headers .= "Reply-To: ".$email."\r\n";
//$headers .= "From: ".$Sender."\r\n";

if (mail($to, $subject, $message, $headers)){
echo("<p>Message successfully sent!</p>");
echo ( '<A href = "index.php">Home Page</A>' );
} else {
echo("<p>Message delivery failed...</p>");
}

?>

UPDATE: So for some reason specifying the sender email address was causing problems with setting the reply-to email address. When I remove the sender email address from the headers now the reply-to is working. I would just forget about the sender address.. who cares where the email came from as long as you can just hit reply on the email and have it go to the users email address.

thanks again.

its not working for me.

i entered a valid email as user email address in the form. after submit, i received email using the above code from webmaster@secureserver.net(gmail inbox).
when i click reply or reply-to all, i see only webmaster@secureserver.net in $TO field. user's valid email address does not show in TO field.

thanks.

Interesting, not really sure what to say. I am testing it on my host and it works perfectly fine. When I hit the reply button it is sending back to the email address that the user had put in to the form.

It could be the mail system that your host is using. I replying to the email using Gmail. If you are using Hotmail it may just be another quark in Hotmail again.

i entered hotmail and gmail in the form. but after getting the email, i click reply-to, but never see hotmail/gmail in TO field. only option receiver has to click the sender email link located at the body of email. pls let me know if u have workground for that.

also, pls let me know if u have any code which sends email to hotmail inbox. service provider told me there is a way to do that. they said once user submit their email, ur hosting email can send the email instead of webmaster. in this case hotmail will get in inbox. not sure what i am talkin about neither him. lol.

thx.

safi
safiullah12@hotmail.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.