Jump to content

[SOLVED] Linked Email in PHP contact form


Apryle

Recommended Posts

I have a php form at http://www.estesparkweddings.com/contactus.shtml

 

the potential client enters an email address (along with other info) that is processed by the below php. When I receive the submitted form via email, the email address the client entered is not a hyperlink, just plain text.

 

The form is working great, so no need to pick apart my code, even if there is a more efficient way to do things (which there usually is). Anyone know how I can get the email address to show up in the email as a link instead of plain text? (I need it to be a universal solution as some of the folks accessing the form have yahoo email, some use Outlook, some use gmail, some use aol, etc.). Thanks!!

 

<?php

 

// get posted data

$EmailFrom = "info@allyourssolutions.com";

$EmailTo = "apryle@allyourssolutions.com";

$Subject = "test request";

$Name = Trim(stripslashes($_POST['Name']));

$Street1 = Trim(stripslashes($_POST['Street1']));

$Street2 = Trim(stripslashes($_POST['Street2']));

$City = Trim(stripslashes($_POST['City']));

$State = Trim(stripslashes($_POST['State']));

$Tel = Trim(stripslashes($_POST['Tel']));

$email1 = Trim(stripslashes($_POST['email1']));

$confirmemail = Trim(stripslashes($_POST['confirmemail']));

$zip = Trim(stripslashes($_POST['zip']));

$bride = Trim(stripslashes($_POST['bride']));

$groom = Trim(stripslashes($_POST['groom']));

$preferredDate = Trim(stripslashes($_POST['preferredDate']));

$alternateDate = Trim(stripslashes($_POST['alternateDate']));

$guests = Trim(stripslashes($_POST['guests']));

$beauty = Trim(stripslashes($_POST['beauty']));

$cakes = Trim(stripslashes($_POST['cakes']));

$cermonySites = Trim(stripslashes($_POST['ceremonySites']));

$consultants = Trim(stripslashes($_POST['constultants']));

$florists = Trim(stripslashes($_POST['florists']));

$gifts = Trim(stripslashes($_POST['gifts']));

$invitations = Trim(stripslashes($_POST['invitations']));

$limos = Trim(stripslashes($_POST['limos']));

$honeymoons = Trim(stripslashes($_POST['honeymoons']));

$music = Trim(stripslashes($_POST['music']));

$rentals = Trim(stripslashes($_POST['rentals']));

$photographers = Trim(stripslashes($_POST['photographers']));

$receptions = Trim(stripslashes($_POST['receptions']));

$videographers = Trim(stripslashes($_POST['videographers']));

$officials = Trim(stripslashes($_POST['officials']));

 

// check for required fields

$validationOK=true;

if (Trim($Name)=="") $validationOK=false;

if (Trim($email1)=="") $validationOK=false;

if (Trim($confirmemail)=="") $validationOK=false;

if (Trim($guests)=="") $validationOK=false;

if (!is_numeric($guests)) $validationOK=false;

if (!$validationOK) {

print "<meta http-equiv=\"refresh\" content=\"0;URL=error1.shtml\">";

exit;

}

 

// email body text

$Body = "";

$Body .= "Name: ";

$Body .= $Name;

$Body .= "\n";

$Body .= "email1: ";

$Body .= $email1;

$Body .= "\n";

$Body .= "confirmemail: ";

$Body .= $confirmemail;

$Body .= "\n";

$Body .= "Tel: ";

$Body .= $Tel;

$Body .= "\n";

$Body .= "Street1: ";

$Body .= $Street1;

$Body .= "\n";

$Body .= "Street2: ";

$Body .= $Street2;

$Body .= "\n";

$Body .= "City: ";

$Body .= $City;

$Body .= "\n";

$Body .= "State: ";

$Body .= $State;

$Body .= "\n";

$Body .= "zip: ";

$Body .= $zip;

$Body .= "\n";

$Body .= "Bride Name: ";

$Body .= $bride;

$Body .= "\n";

$Body .= "Groom Name: ";

$Body .= $groom;

$Body .= "\n";

$Body .= "guests: ";

$Body .= $guests;

$Body .= "\n";

$Body .= "Preferred Date: ";

$Body .= $preferredDate;

$Body .= "\n";

$Body .= "Alternate Date: ";

$Body .= $alternateDate;

$Body .= "\n";

$Body .= "Ceremony Location: ";

$Body .= $ceremony;

$Body .= "\n";

$Body .= "\n";

$Body .= "Info has been requested in the following Categories:";

$Body .= "\n";

 

if ($beauty == beauty){

$Body .= "Beauty Information Requested ";

$Body .= "\n";

}

else{

$Body .= " ";

}

 

if ($cakes == cakes){

$Body .= "Cakes and Catering Information Requested ";

$Body .= "\n";

}

else{

$Body .= " ";

}

 

if ($ceremonySites == ceremonySites){

$Body .= "Ceremony Sites Information Requested ";

$Body .= "\n";

}

else{

$Body .= " ";

}

 

if ($consultants == consultants){

$Body .= "Consultants Information Requested ";

$Body .= "\n";

}

else{

$Body .= " ";

}

 

 

// send email

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

 

// redirect to thank you page

if ($success){

print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.shtml\">";

}

else{

print "<meta http-equiv=\"refresh\" content=\"0;URL=error2.shtml\">";

}

?>

Link to comment
Share on other sites

Wow, that script is a shit-ton bigger than it should be (but that's for another day!). You could send the e-mail as an HTML email and create the hyperlink with an anchor tag. You'd need to pass the correct headers in the email though for the client to decode it as HTML. Check out the comments on the manual page for the mail() function, there is further information there of how this can be achieved.

Link to comment
Share on other sites

$Body .= "confirmemail: ";
$Body .= "<a href=\"mailto:{$confirmemail}\">{$confirmemail}</a>";

 

Once you've got the headers fixed to send a HTML email, that's the bit you need to change.

 

I agree, your script needs shortening.. a lot ;)

Link to comment
Share on other sites

you need to add headers to your mail function in order for you to send html format emails.

 

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

 

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?> 

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.