Jump to content

need help in mail function


doforumda

Recommended Posts

hi

 

i create a contact form. When user send me a message then at From column in my inbox i see something like this "[email protected]". It should be "My Web". How can i make it to My Web instead of "[email protected]"

 

here is mu code

<?php
$name = strip_tags(addslashes($_POST['name']));
$email = strip_tags(addslashes($_POST['email']));
$message = strip_tags(addslashes($_POST['msg']));

if($name) {
if($email) {
	if(ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
		if($message) {
			$to = "[email protected]";
			$from = "My Web";
			$msg = $message;
			$subject = "Message from zafarsaleem.info";

			$mail = mail($to,$subject,$msg,$from);
			//$mail = true;
			if($mail) {
				echo "Your message has been sent. Thank you for contacting.";
			}
			else
				echo "Sending message failed. Please try again later.";
		}
		else
			echo "Enter your message.";
	}
	else
		echo "Enter valid email address.";
}
else
	echo "Your email is required.";
}
else
echo "Your name is required.";
?>

Link to comment
https://forums.phpfreaks.com/topic/199578-need-help-in-mail-function/
Share on other sites

http://docs.php.net/manual/en/function.mail.php

 

The last argument is not the name of the sender, but the list of additional mail headers. In other words, you must prepare a complete From header, like this:

 

mail($to, $subject, $message, 'From: Me <[email protected]>');

 

 

Look at this taken from php.net.

 

<?php

$Name = "Da Duder"; //senders name
$email = "[email protected]"; //senders e-mail adress
$recipient = "[email protected]"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

ini_set('sendmail_from', '[email protected]'); //Suggested by "Some Guy"

mail($recipient, $subject, $mail_body, $header); //mail command 
?>

 

James.

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.