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 "example@eg.justhost.com". It should be "My Web". How can i make it to My Web instead of "example@eg.justhost.com"

 

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 = "web@example.com";
			$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
Share on other sites

Look at this taken from php.net.

 

<?php

$Name = "Da Duder"; //senders name
$email = "email@adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt@emailadress.com"; //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', 'me@domain.com'); //Suggested by "Some Guy"

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

 

James.

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.