Ryan Fitton
08-12-2010, 07:14 PM
Hi there, I already have a PHP script that sends an email to me when someone used the contact form on my website, but the email I receive is just standard text, how can i add hyperlinks and images into this script? My script is below:
<?php
function domain_exists($email,$record = 'MX')
{
list($user,$domain) = split('@',$email);
return checkdnsrr($domain,$record);
}
function isValidEmail($address) {
return preg_match("/^[a-z0-9._\-]+[@]([a-z0-9\-]+[.])+([a-z]{2,4})\$/i",
$address);
}
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('Europe/London');
// get posted data into local variables
$EmailFrom = "ryan.fitton@googlemail.com";
$EmailTo = "ryan.fitton@googlemail.com";
$Subject = "Email From Personal Website";
$YourName = Trim(stripslashes($_POST['YourName']));
$YourEmail = Trim(stripslashes($_POST['YourEmail']));
$YourMessage = Trim(stripslashes($_POST['YourMessage']));
$YourIP = Trim(stripslashes($_POST['IP']));
$Date = date("d M Y");
$Time = date("h:i A");
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=/contact_error.php\">";
exit;
}
// Check if required fields are filled in
if(trim($YourName) == '' || trim($YourEmail) == '' || trim($YourMessage) == '') {
print "<meta http-equiv=\"refresh\" content=\"0;URL=/contact_error.php\">";
exit;
}
// check for a valid email
if(!isValidEmail($YourEmail) || !domain_exists($YourEmail))
die("<meta http-equiv=\"refresh\" content=\"0;URL=/contact_error.php\">");
else {
// prepare email body text
$Body .= "Ryan Fitton, you have recieved an email from the contact form on your website.";
$Body .= "\n\n";
$Body .= "This message was sent on the ";
$Body .= $Date;
$Body .= " at ";
$Body .= $Time;
$Body .= "\n\n";
$Body .= "--------------------------------------";
$Body .= "\n";
$Body .= "IP Adresses: ";
$Body .= $IP=$_SERVER['REMOTE_ADDR'];
$Body .= "\n\n";
$Body .= "Name: ";
$Body .= $YourName;
$Body .= "\n\n";
$Body .= "Email: ";
$Body .= $YourEmail;
$Body .= "\n\n";
$Body .= "Message: ";
$Body .= $YourMessage;
$Body .= "\n";
$Body .= "--------------------------------------";
$Body .= "\n\n\n";
$Body .= "This email has arrived from http://www.ryanfitton.co.uk and is private for Ryan Fitton (ryan.fitton@hotmail.co.uk). If you are not Ryan Fitton and you have recieved this email, please contact me using this email address: ryan.fitton@hotmail.co.uk";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=/contact_sent.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=/contact_error.php\">";
}
}
?>
I want to add an hyperlink using html for example:
<a href='http://www.google.co.uk'>Clike here to access Google</a>
I want to have this somewhere in the body tags, such as:
$Body .= "Ryan Fitton, you have recieved an email from the contact form on your website here: <a href='http://www.google.co.uk'>Clike here to access Google</a>";
<?php
function domain_exists($email,$record = 'MX')
{
list($user,$domain) = split('@',$email);
return checkdnsrr($domain,$record);
}
function isValidEmail($address) {
return preg_match("/^[a-z0-9._\-]+[@]([a-z0-9\-]+[.])+([a-z]{2,4})\$/i",
$address);
}
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('Europe/London');
// get posted data into local variables
$EmailFrom = "ryan.fitton@googlemail.com";
$EmailTo = "ryan.fitton@googlemail.com";
$Subject = "Email From Personal Website";
$YourName = Trim(stripslashes($_POST['YourName']));
$YourEmail = Trim(stripslashes($_POST['YourEmail']));
$YourMessage = Trim(stripslashes($_POST['YourMessage']));
$YourIP = Trim(stripslashes($_POST['IP']));
$Date = date("d M Y");
$Time = date("h:i A");
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=/contact_error.php\">";
exit;
}
// Check if required fields are filled in
if(trim($YourName) == '' || trim($YourEmail) == '' || trim($YourMessage) == '') {
print "<meta http-equiv=\"refresh\" content=\"0;URL=/contact_error.php\">";
exit;
}
// check for a valid email
if(!isValidEmail($YourEmail) || !domain_exists($YourEmail))
die("<meta http-equiv=\"refresh\" content=\"0;URL=/contact_error.php\">");
else {
// prepare email body text
$Body .= "Ryan Fitton, you have recieved an email from the contact form on your website.";
$Body .= "\n\n";
$Body .= "This message was sent on the ";
$Body .= $Date;
$Body .= " at ";
$Body .= $Time;
$Body .= "\n\n";
$Body .= "--------------------------------------";
$Body .= "\n";
$Body .= "IP Adresses: ";
$Body .= $IP=$_SERVER['REMOTE_ADDR'];
$Body .= "\n\n";
$Body .= "Name: ";
$Body .= $YourName;
$Body .= "\n\n";
$Body .= "Email: ";
$Body .= $YourEmail;
$Body .= "\n\n";
$Body .= "Message: ";
$Body .= $YourMessage;
$Body .= "\n";
$Body .= "--------------------------------------";
$Body .= "\n\n\n";
$Body .= "This email has arrived from http://www.ryanfitton.co.uk and is private for Ryan Fitton (ryan.fitton@hotmail.co.uk). If you are not Ryan Fitton and you have recieved this email, please contact me using this email address: ryan.fitton@hotmail.co.uk";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=/contact_sent.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=/contact_error.php\">";
}
}
?>
I want to add an hyperlink using html for example:
<a href='http://www.google.co.uk'>Clike here to access Google</a>
I want to have this somewhere in the body tags, such as:
$Body .= "Ryan Fitton, you have recieved an email from the contact form on your website here: <a href='http://www.google.co.uk'>Clike here to access Google</a>";