I have made a form for registration by php .The form has submitter email address field.I want that after form submission , form content will send to both form submitter and admin via submitter email address and admin email address. Submitter email address will get from submitter email address field.Admin email address is fixed .
For Submitter
headers= "from : no-reply#eschool.com"
messagebody same as it is
For admin
headers=" from :$email"
messagebody same as it is
I tried to do this:
Html code:
<form action="action.php" method="post">
<table>
<tr>
<td>Name</td>
<td>:</td>
<td><input type="text" name="name" width="400" /></td>
</tr>
<tr>
<td>Address</td>
<td>:</td>
<td><input type="text" name="address" width="400" /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type="text" name="email" width="400" /></td>
</tr>
<tr>
<td>Password</td>
<td rowspan="2"> </td>
<td>
<p><input type="text" name="pass" width="400" /></p>
<p> </p>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="insert" value="Insert" /></td>
</tr>
</table>
<input type="submit" value="submit" />
</form>
action.php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
$to = $email . "," . $admin;
$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/plain;charset=UTF-8;" . "\n";
$headers .= "content-Transfer-encoding: 8bit" ."\n";
$headers .= "From: no-reply#eschool.com ". "\n";
mail($to, $subject, $email_message, $headers);
Thanks
Your code is perfect, what is your are facing problem, plz write your problem.
Make following change in action.php for your convenience :
<?php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
//$to = $email $admin;
$email_message = '';
$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers1 = 'MIME-Version: 1.0' . "\r\n";
$headers1 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers1 .= "From: no-reply#eschool.com ". "\n";
$headers2 = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
$headers2 .= "From: ". $email . "\n";
if(#mail( $email, $subject, $email_message , $headers1 )) {
#mail( $admin, $subject, $email_message , $headers2 )
echo "Mail Sent.";
} else {
echo "Mail Not Sent.";
}
?>
You can simply make two different versions of your headers and execute mail(...) twice:
<?php
$name = $_POST["name"];
$address = $_POST["address"];
$email = $_POST["email"];
$password = $_POST['pass'];
$subject = "Thank you for your registration.";
$admin = "info#editor.com";
$email_message = "Name: ".$name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type:text/plain;charset=UTF-8;\n";
$headers .= "content-Transfer-encoding: 8bit\n";
$poster_headers = $headers . "From: no-reply#eschool.com\n";
$admin_headers = $headers . "From: ".$email."\n";
mail( $admin, $subject, $email_message, $admin_headers );
mail( $email, $subject, $email_message, $poster_headers );
?>
Related
I would like to send a confirmation email to the user who submitted the form and another email to me with the details which the user inputted, here is my form:
<form class="" action="." id="dateForm" method="POST">
<input type="text" class="form-control" id="dfName" placeholder="Name" required>
<input type="email" class="form-control" id="dfEmail" placeholder="Email" required>
<input type="tel" class="form-control" id="dfPhone" placeholder="Phone Number" required>
<input type="text" class="form-control" id="dfDate" placeholder="Schedule a call" required>
<textarea id="dfMessage" rows="5" class="form-control" placeholder="Your Message" required></textarea>
<button type="submit" class="">SUBMIT</button>
</form>
And here is my php which works perfect for sending the emails to me.
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$date = trim($_POST['date']);
$message = trim($_POST['message']);
function is_email_valid($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
if( isset($name) && isset($email) && isset($phone) && isset($date) && isset($message) && is_email_valid($email) ) {
$to = "myemail#gmail.com";
$subject = "New inquiry request from Olho";
$body = <<<EOD
<strong>Name:</strong> $name <br>
<strong>Email:</strong> $email <br> <br>
<strong>Phone:</strong> $phone <br>
<strong>Booking Date:</strong> $date <br>
<strong>Message:</strong> $message <br>
EOD;
$headers = "From: $name <$email>\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $body, $headers);
So what I would like is to receive another email after the one send to me which will contain a confirmation message like "Thank you for contacting us, we will get back to you as soon as possible."
I've tried to use this but I am not receiving the confirmation email:
$conf_subject = 'Your recent enquiry';
$conf_sender = 'Olho';
$msg = $name . ",\n\nThank you for your recent enquiry. A member of our
team will respond to your message as soon as possible.";
$headers2 = "From: $conf_sender <myemail#gmail.com>\r\n";
$headers2 .= 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail( $email, $conf_subject, $msg, $headers2 );
You should wait for first mail to be completed and then should send second email as below code:
if (mail($to, $subject, $body, $headers)) {
$conf_subject = 'Your recent enquiry';
$conf_sender = 'Olho';
$msg = $name . ",\n\nThank you for your recent enquiry. A member of our
team will respond to your message as soon as possible.";
$headers2 = "From: $conf_sender <myemail#gmail.com>\r\n";
$headers2 .= 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail( $email, $conf_subject, $msg, $headers2 );
}
Hope it helps you.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I am trying to execute "Tell a friend" php script, but that is not sending any emails, not to admin, friends, sender. Other emails on same server working fine.
I don't understand why this is not working, as other emails pages like contact us, registration (which send confimation email) all working on same server, please help me..
Html Code:
<table>
<tr>
<td>
<span>Complete the details below to send this link to a friend:</span>
<?php
$refurl = $_SERVER['HTTP_REFERER'];?>
<span><? print $refurl;?></span>
<form name="tellafriend" action="send_group.php" method="post" onSubmit="return checkfields()">
<table>
<tr>
<td> Your name*:</td>
<td> <input name="name" size="30" maxlength="45"> </td>
</tr>
<tr>
<td>Your email*:</td>
<td><input name="email" size="30" maxlength="45"></td>
</tr>
<tr>
<td colspan="2"><p align="center">Enter your friend's email addresses:</p>
</td>
</tr>
<tr>
<td>Email 1*:</td>
<td><input name="fmail1" class="bordesolid1" size="30" maxlength="50"></td>
</tr>
<tr>
<td>Email 2*:</td>
<td><input name="fmail2" size="30" maxlength="50"></td>
</tr>
<tr>
<td>Email 3*:</td>
<td><input name="fmail3" size="30" maxlength="50"></td>
</tr>
<tr>
<td colspan="2"><p align="center"><span>This message will contain your name & email address.</span>
<br>
<input onClick="validate();" type="button" value="click once to send">
<input type=hidden name=refurl value="<? print $refurl;?>">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
PHP Code:
<?php
if(count($_POST)) {
foreach(array('fmail1','fmail2','fmail3','email','name') as $key) $_POST[$key] = strip_tags($_POST[$key]);
if(!is_secure($_POST)) {
die("Peace People! Stop Spamming!");
}
$name = $_POST[name];
$email = $_POST[email];
$fmail1 = $_POST[fmail1];
$fmail2 = $_POST[fmail2];
$fmail3 = $_POST[fmail3];
$refurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$to = "arvindsri123#yahoo.com";
$subject = "Recommendation form submission";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n".
'X-Mailer: PHP/' . phpversion();
$message = '<html><body>';
$message.='<p style="margin-top:10px;">'.$name.' has used your recommendation form using an email address of '.$email.' </p>';
$message.='<p style="margin-top:10px;">The people the recommendation has been submitted to are: </p>';
$message.='<p style="margin-top:10px;">'.$fmail1.' </p>';
$message.='<p style="margin-top:10px;">'.$fmail2.' </p>';
$message.='<p style="margin-top:10px;">'.$fmail3.' </p>';
$message.='<p style="margin-top:10px;">The page recommended:</p>';
$message.='<p style="margin-top:10px;">'.$refurl.'</p>';
$message .= '</body></html>';
$sentmail = mail($to, $subject, $message, $headers);
// $thankyoupage = "thankyou.htm";
//echo $sentmail;
if($sentmail) {
$name = $_POST[name];
$email = $_POST[email];
$fmail1 = $_POST[fmail1];
$fmail2 = $_POST[fmail2];
$fmail3 = $_POST[fmail3];
$refurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$tsubject = "A web page recommendation from $_POST[name]";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n".
'X-Mailer: PHP/' . phpversion();
$message = '<html><body>';
$message.='<p style="margin-top:10px;">Hi, '.$name.' whose email address is $_POST[email] thought you may be interested in this web page. '.$email.' </p>';
$message.='<p style="margin-top:10px;">'.$refurl.'</p>';
$message .= '</body></html>';
$sentmail = mail($fmail1,$fmail2,$fmail3, $tsubject $message, $headers);
echo '<h4>You have sent emails...</h4>';
//header("Location: $thankyoupage");
exit;
}
function is_secure($ar) {
$reg = "/(Content-Type|Bcc|MIME-Version|Content-Transfer-Encoding)/i";
if(!is_array($ar)) {
return preg_match($reg,$ar);
}
$incoming = array_values_recursive($ar);
foreach($incoming as $k=>$v) if(preg_match($reg,$v)) return false;
return true;
}
function array_values_recursive($array) {
$arrayValues = array();
foreach ($array as $key=>$value) {
if (is_scalar($value) || is_resource($value)) {
$arrayValues[] = $value;
$arrayValues[] = $key;
}
elseif (is_array($value)) {
$arrayValues[] = $key;
$arrayValues = array_merge($arrayValues, array_values_recursive($value));
}
}
return $arrayValues;
}
?>
I am using Bluehost web hosting, and other emails properly working as I said Contact us, Registration confirmation emails.. etc.
Thanks!
If you are running on localhost then it won't send email.. to do so you need to host on server
Try to host on free hosting server.. it will work!
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am using PHP mail function to send a mail, But am testing my local sever mail has been sent but my live i cant sent mail. Can you please help me?
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: <'.$_POST['email'].'>' . "\r\n";
$to = "xxxxxxx#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
} else {
echo "Cannot Send Email ";
}
Why use mail() when you have codeigniter email class.
$this->load->library('email');
$this->email->from('your#example.com', 'Your Name');
$this->email->to('someone#example.com');
$this->email->cc('another#another-example.com');
$this->email->bcc('them#their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
Use mandrillapp for sending mail using SMTP, and add credentials for email class.
Try it. It's Working
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: '.$_POST['email'].'' . "\r\n";
$CusHeaders .= 'Reply-To: '.$_POST['email'].'' . "\r\n";
$CusHeaders .= 'X-Mailer: PHP/' . phpversion();
$to = "xxxxxxx#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
} else {
echo "Cannot Send Email ";
}
Use this as html(test)
<form action="#" method="post">
<input type="text" name="name" placeholder="name" />
<input type="text" name="email" placeholder="email"/>
<input type="text" name="phone" placeholder="phone" />
<input type="text" name="message" placeholder="message"/>
<input type="submit" name="submit"/>
</form>
PHP
if(isset($_POST[submit]))
{
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: <'.$_POST['email'].'>' . "\r\n";
$to = "p******#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
}
else {
echo "Cannot Send Email ";
}
}
?>
Oke, this is a tricky one. (I think).
Do you know when you receive a message and the email has a image on top or on the bottom of the page.
I have been trying to make it but can't figure it out.
I hope you guy's can help me with this problem.
This is what I got so far;
<?php
$to = 'info#gmail.com';
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$gast = $_POST['email'];
$tmpName = $_FILES['attachment']['tmp_name'];
$fileType = $_FILES['attachment']['type'];
$fileName = $_FILES['attachment']['name'];
if(empty($errors))
{
$to = $to;
$from = $gast;
$file = fopen($tmpName,'rb');
$data = fread($file,filesize($tmpName));
fclose($file);
$mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";
$body = "E-mail".
"Name: $name\n".
"Email: $gast \n".
"Content-Type: {$fileType};\n".
"Content-Transfer-Encoding: base64\n\n".
$data;
$headers = "From: $from \r\n";
$headers .= "Email: $gast \r\n";
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative;\n";
$headers .= " boundary=\"{$mimeBoundary}\"";
$headers .= "img src='http://cache.estivant.nl/image/1399025430_12_banners-bestemmingen-single-1680x460-extra2-06-kos_1399025430.jpg' alt='image'";
$data = chunk_split(base64_encode($data));
mail($to, $body, $headers);
}
}
?>
<html>
<head></head>
<body>
<form method="post" action="">
<label for="name">name</label>
<input type="name" name="name" value="" />
<label for="email">email</label>
<input type="email" name="email" value="" />
<button id="submit" name="submit">send</button>
</form>
</body>
</html>
Simply write a html page with css styles and format your email accordingly and use the html as your email body. This will create an image in the mail
<img src="image.jpg" alt="image"></img>
Please be aware that most (if not all) email clients will block your image from being showed to your receiver as long as you are not in their trusted sender list or contact list.
Of course, your email has to be sent as html
Here is an example of a nicely formatted email with images.
Note image syntax: <img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />'
$to = 'bob#example.com';
$subject = 'Website Change Request';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['req-name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>";
$message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
$message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
$message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
$addURLS = $_POST['addURLS'];
if (($addURLS) != '') {
$message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . strip_tags($addURLS) . "</td></tr>";
}
$curText = htmlentities($_POST['curText']);
if (($curText) != '') {
$message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>";
}
$message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
Code source and full explanation: http://css-tricks.com/sending-nice-html-email-with-php/
I´m trying to validate a simple PHP form with HTML code but it doesn´t work properly.
Here you are HTML code:
<form action="expresscontactform.php" method="post" name="form1" id="form1">
<label>Name </label><input id="Name" name="Name" type="text" value="<?php echo $_POST['Name']; ?>">
<span class="error"> <?php echo $errors[1]; ?> </span>
<label>Email </label><input id="Email" name="Email" type="text" value="<?php echo $_POST['Email']; ?>">
<span class="error"> <?php echo $errors[4]; ?> </span>
<label>Phone </label><input id="Phone" name="Phone" type="text" value="<?php echo $_POST['Phone']; ?>">
<span class="error"> <?php echo $errors[2]; ?> </span>
<label>Country of origin</label><input id="Country" name="Country" type="text" value="<?php echo $_POST['Country']; ?>">
<span class="error"> <?php echo $errors[3]; ?> </span>
<label>Message </label><textarea id="message" cols="5" rows="5" name="Message"></textarea>
<input value="Send" class="send_request_new" type="submit">
</form>
And this is PHP code (on the server):
<?php
if(isset($_POST['send_request_new'])){
$errors = array();
if($_POST['Name'] == ''){
$errors[1] = '<span class="error">Please type your name</span>';
}else if($_POST['Phone'] == ''){
$errors[2] = '<span class="error">Please type your phone number</span>';
}else if($_POST['Country'] == ''){
$errors[3] = '<span class="error">Please type your country</span>';
}else{
$EmailFrom = Trim(stripslashes($_POST['Email']));
$EmailTo = 'webmaster#theacademy.co,' . $EmailFrom;
$Subject = "Online Application Form";
$name = Trim(stripslashes($_POST['Name']));
$phone = $_POST['Phone'];
$country = $_POST['Country'];
$message = $_POST['Message'];
$header = 'From: ' . $EmailFrom . " \r\n";
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/plain";
// prepare email body text
$Body .= "Contact form";
$Body .= "\n";
$Body .= "\n";
$Body .= "This is an automatically generated e-mail, to inform you that we received your request. We will contact you as soon as possible.";
$Body .= "\n";
$Body .= "\n";
$Body .= "Kind regards";
$Body .= "\n";
$Body .= "\n";
$Body .= "**********************************************";
$Body .= "\n";
$Body .= "\n";
$Body .= "The Academy";
$Body .= "\n";
$Body .= "\n";
$Body .= "::::::::::::::::::::::::::";
$Body .= "\n";
$Body .= "Your Request:";
$Body .= "\n";
$Body .= "::::::::::::::::::::::::::";
$Body .= "\n";
$Body .= "\n";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "\n";
$Body .= "Country: ";
$Body .= $country;
$Body .= "\n";
$Body .= "\n";
$Body .= "Email: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
$Body .= "\n";
$Body .= "Sent on " . date('d/m/Y', time());
$Body .= "\n";
$Body .= "\n";
$Body .= "Last visited page: ";
$Body .= $_SERVER['HTTP_REFERER'];
if(mail($EmailTo, $Subject, $Body, $header)){
$result = '<div class="result_ok">Email sent successfully</div>';
// If successfully we reset all the fields
$_POST['nombre'] = '';
$_POST['email'] = '';
$_POST['asunto'] = '';
$_POST['mensaje'] = '';
header("refresh:3;url=http://www.myexample.co/");
}else{
$result = '<div class="result_fail">Error!!</div>';
}
}
}
?>
I think there is a mistake in the line below:
<span class="error"> <?php echo $errors[1]; ?> </span>
But I don´t know where exactly.
One more question, how can I set "The Academy" as email sender?
I don´t know if this is the best way to validate a form, if someone show me other way I will be thankful to learn.
I appreciate a lot if anyone can help me, please.
Thanks in advance.
Firstly, your code's execution is dependant on this conditional statement if(isset($_POST['send_request_new'])) where it's looking for a "named" element called send_request_new therefore would never execute.
Your present (unnamed) submit button
<input value="Send" class="send_request_new" type="submit">
this should be changed to:
<input value="Send" class="send_request_new" type="submit" name="send_request_new">
you have a class named that way, instead of a name.
In order to get it to work, you would need to place your entire HTML/PHP inside the same page and use action=""
I noticed you don't have one for your Email and the message, only for the name/phone number and country.
Plus, to use a personalized method for the sender's name:
Base yourself on the following:
$Name = "The Academy";
$email = "email#example.com";
$header = "From: ". $Name . " <" . $email . ">\r\n";
You can use some of the filters on PHP.net to validate and protect against XSS injection:
-http://php.net/manual/en/filter.filters.validate.php
One of which being FILTER_VALIDATE_EMAIL