Jump to content

Recommended Posts

Hi Guys how is everyone today, quick question I know one of you will answer this no problem. I have created a php contact form that once info is filled out it goes to the database and emails me, also it sends them a response which is working fine, the problem I have is I can't get html links to work when they receive the auto response email. I changed the text to red to indicate which text I want to link to a website

 

Please see my script below I appreciate all the help I can get I have just started with php so I will be very grateful

 

<?php

// Connect to database
$hostname = "0.0.0.0";
$username = "";
$password = "";
$dbname = "";
$usertable = "";
$f_name = $_REQUEST['f_name'];
$postcode = $_REQUEST['postcode'];
$tel = $_REQUEST['tel'];
$mobile = $_REQUEST['mobile'];
$email = $_REQUEST['email'];
$course = $_REQUEST['course'];

mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");

$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");

$errmsg  = ''; // error message
$f_name   = ''; // sender's name
$postcode   = ''; // sender's name
$tel = ''; // message tel
$mobile = ''; // message tel
$email   = ''; // sender's email addres
$course = ''; // the message itself

if(isset($_POST['send']))
{
   $f_name   = $_POST['f_name'];
   $postcode   = $_POST['postcode'];
   $tel = $_POST['tel'];
   $mobile = $_POST['mobile'];
   $email = $_POST['email'];
   $course = $_POST['course'];
   
   if(trim($f_name) == '')
   {
      $errmsg = 'Please enter your name';
   }
   else if(trim($postcode) == '')
   {
      $errmsg = 'Please enter your postcode';
   }
   else if(trim($tel) == '')
   {
      $errmsg = 'Please enter Your Telephone Number:';
   }
   else if(trim($mobile) == '')
   {
      $errmsg = 'Please enter your mobile';
   }    
   else if(trim($email) == '')
   {
      $errmsg = 'Please enter your email address';
   }
   else if(!isEmail($email))
   {
      $errmsg = 'Your email address is not valid';
   }
   else if(trim($course) == '')
   {
      $errmsg = 'Please enter the course your interested in';
   }   
   if($errmsg == '')
   {
      if(get_magic_quotes_gpc())
      {
         $tel = stripslashes($tel);
         $message = stripslashes($message);
      }   
      
      $query = "INSERT INTO table (id, f_name, postcode, tel, mobile, email, course, pdate) VALUES ('', '$f_name', '$postcode', '$tel', '$mobile', '$email' , '$course', NOW())";
      
      $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable");
      
      
      
      // the email will be sent here
      $to      = "email address";
      
      $user_message .= "Name: $f_name \r\n"; 
        $user_message .= "postcode: $postcode \r\n";
        $user_message .= "tel: $tel \r\n"; 
        $user_message .= "mobile: $mobile \r\n"; 
        $user_message .= "email: $email \r\n"; 
        $user_message .= "course: $course \r\n";
        $headers = "- Enquiry \r\n"; 
        $headers .= "Reply-To: $email"; 
      
      mail('email','Enquiry',$user_message,$headers);
      
$autoreply="Thank you for your enquiry, $f_name.

Congratulations you have just taken one step closer to gaining your dream job

[color=red] Click Here to find out how to Dress for success
[/color]

[color=red]Click Here for tips to Look good feel good[/color]

[color=red]Find the best methods to Plan your day Click here
[/color]
[color=red]Click Here to find out more
[/color]
[color=red]Click Here for 10 ten tips for communicating 
[/color]

Contact us now to find out more



This is an automated reply.";

$subject="Thank you for Enquiring $name!

";

mail($email, $subject, $message, $autoreply);
?>
</span>
<div align="center" class="boldenquire style5">Well done! you have just taken the first step in securing that dream job. Please check your email now to get you started</div>
<?php
   }
}

mysql_close();

if(!isset($_POST['send']) || $errmsg != '')
{
?>
<div align="center" class="ermsg"><?=$errmsg;?></div>
<form  method="post" name="msgform" id="msgform">
  <table border="0" align="center" cellpadding="2" cellspacing="1" class="maincell">
    <tr>
      <td align="center" class="boldenquire2" colspan="2">It's Your Career    </tr>
    <tr>
      <td>Your Name:</td>
      <td><input name="f_name" type="text" class="eqform" style="width:100px" value="<?=$f_name;?>" /></td>
    </tr>
    <tr>
      <td>Nearest centre:</td>
      <td><label>
        <select name="postcode" size="1" class="eqform" style="width:100px" value=" <?=$postcode;?>">
          <option value="Gravesend">Gravesend</option>
          <option value="Maidstone">Maidstone</option>
          <option value="Bromley">Bromley</option>
          <option value="Chatham">Chatham</option>
          <option value="Croydon">Croydon</option>
          <option value="Dartford">Dartford</option>
          <option value="Tunbridge Wells">Tunbridge Wells</option>
        </select>
      </label></td>
    </tr>
    <tr>
      <td>Address:</td>
      <td><label>
        <textarea name="textarea" rows="5" class="eqform" id="textarea"></textarea>
      </label></td>
    </tr>
    <tr>
      <td>Tel:</td>
      <td><input name="tel" type="text" class="eqform" style="width:100px" value="<?=$tel;?>" /></td>
    </tr>
    <tr>
      <td>Mobile:</td>
      <td><input name="mobile" type="text" class="eqform" style="width:100px" value="<?=$mobile;?>" /></td>
    </tr>
    <tr>
      <td>Email:</td>
      <td><input name="email" type="text" class="eqform" style="width:100px" value="<?=$email;?>" /></td>
    </tr>
    <tr>
      <td><span class="req">What is your ideal job:</span></td>
      <td><input name="course" type="text" class="eqform" style="width:100px" value="<?=$course;?>" size="40" />      </td>
    </tr>
    <tr align="center">
      <td colspan="2" class="boldenquire2"><input name="send" type="submit" class="eqbox" onClick="return checkForm();" value="Click Here" />
        <br />
<span class="boldenquire2">For 5 ways to get that dream job</span></td>
    </tr>
    <tr align="left">
      <td colspan="2"><br />
          <script language="JavaScript">
      var addr = '';
      var host = '';
      var email = '';
      document.write(email);
      </script></td>
    </tr>
  </table>
</form>
<?php
}

function isEmail($email)
{
   return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
         ,$email));
}
?>

Link to comment
https://forums.phpfreaks.com/topic/159831-help-with-php-contact-autoresponse/
Share on other sites

Mr Adam

 

thanks for helping me, I did try that but when the auto response gets sent to outlook it just gets displayed like this

 

<html>
<head>
  <title>Birthday Reminders for August</title> </head> <body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>

 

please help, I am new to php and I did have hair this morning

Hi guys thanks for your help so far this is what I have below the auto responder is working but I am not getting any of the html, all that I am receiving is

 

MIME-Version: 1.0

Content-type: text/html; charset=iso-8859-1

To: Mary <mary@example.com>, Kelly <kelly@example.com>

From: Birthday Reminder <birthday@example.com>

Cc: birthdayarchive@example.com

Bcc: birthdaycheck@example.com

 

this is a section of code

 

 

// the email will be sent here

$to      = "com";

 

$user_message .= "Name: $f_name \r\n";

        $user_message .= "postcode: $postcode \r\n";

        $user_message .= "tel: $tel \r\n";

        $user_message .= "mobile: $mobile \r\n";

        $user_message .= "email: $email \r\n";

        $user_message .= "course: $course \r\n";

        $headers = "- Enquiry \r\n";

        $headers .= "Reply-To: $email";

 

mail('.com',' Enquiry',$user_message,$headers);

 

$autoreply="Thank you for your enquiry, $f_name.";

 

// message

$message = '

<html>

<head>

<title>5 Ways to get that dream job!</title>

</head>

 

<body>

<p>Congratulations  you have just taken one step closer to gaining your dream job</p>

<ol>

  <li>In an interview situation, you are  marketing yourself as a product, so you need to make the best personal impact  possible.<a href="www..com/pdfs/Dressing for success.pdf">Click Here</a> to find out how to "Dress for success"</li>

  <li>Image is important if we want to create a  good impression. More importantly, our image has an overall effect on how we  feel about ourselves. <a href="www..com/pdfs/Look good, feel good.pdf">Click Here</a> for tips to "Look good feel good"</li>

  <li>Modern life seems to get increasingly hectic every day.  We seem to have more and more tasks to do, either  at work or in our personal lives, and less and less time to do them. Find the  best methods to "Plan your  day" <a href="http://www.com/pdfs/plan your day.pdf">Click here</a></li>

  <li>Your CV is an  essential document needed to present yourself effectively in the job market. "The perfect cv" will considerably boost your chances <a href="www.com/pdfs/The Perfect CV.pdf">Click Here</a> to find out more </li>

  <li>“Great communication relies on a willingness to communicate whether you are sending or receiving a message. <a href="www./pdfs/top ten tips for communicating successfully.pdf">Click Here</a> for "10 ten tips for communicating "</li>

</ol>

<p>Most importantly of all  .</p>

<p>Contact us now to find  out more</p>

<p>Text</p>

<p> </p>

<p> </p>

</body>

</html>

 

';

 

// To send HTML mail, the Content-type header must be set

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 

// Additional headers

$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";

$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";

$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";

$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

 

$subject="Thank you for Enquiring  $name!

 

";

 

mail($email, $subject, $headers, $autoreply);

?>

</span>

<div align="center" class="boldenquire style5">Well done! you have just taken the first step in securing that dream job. Please check your email now to get you started</div>

<?php

}

}

 

mysql_close();

 

if(!isset($_POST['send']) || $errmsg != '')

{

?>

<div align="center" class="ermsg"><?=$errmsg;?></div>

<form  method="post" name="msgform" id="msgform">

  <table border="0" align="center" cellpadding="2" cellspacing="1" class="maincell">

    <tr>

      <td align="center" class="boldenquire2" colspan="2">Fill in the form   

    </tr>

    <tr>

      <td align="left">Your Name:</td>

      <td align="left"><input name="f_name" type="text" class="eqform" style="width:100px" value="<?=$f_name;?>" /></td>

    </tr>

    <tr>

      <td align="left">Nearest centre:</td>

      <td align="left"><label>

        <select name="postcode" size="1" class="eqform" style="width:100px" value=" <?=$postcode;?>">

          <option value="Gravesend">Gravesend</option>

          <option value="Maidstone">Maidstone</option>

          <option value="Bromley">Bromley</option>

          <option value="Chatham">Chatham</option>

          <option value="Croydon">Croydon</option>

          <option value="Dartford">Dartford</option>

          <option value="Tunbridge Wells">Tunbridge Wells</option>

        </select>

      </label></td>

    </tr>

    <tr>

      <td align="left">Address:</td>

      <td><label>

        <textarea name="textarea" rows="5" class="eqform" id="textarea"></textarea>

      </label></td>

    </tr>

    <tr>

      <td align="left">Tel:</td>

      <td align="left"><input name="tel" type="text" class="eqform" style="width:100px" value="<?=$tel;?>" /></td>

    </tr>

    <tr>

      <td align="left">Mobile:</td>

      <td align="left"><input name="mobile" type="text" class="eqform" style="width:100px" value="<?=$mobile;?>" /></td>

    </tr>

    <tr>

      <td align="left">Email:</td>

      <td align="left"><input name="email" type="text" class="eqform" style="width:100px" value="<?=$email;?>" /></td>

    </tr>

    <tr>

      <td align="left"><span class="req">What is your ideal job:</span></td>

      <td align="left"><input name="course" type="text" class="eqform" style="width:100px" value="<?=$course;?>" size="40" /></td>

    </tr>

    <tr align="center">

      <td colspan="2" class="boldenquire2"><input name="send" type="submit" class="eqbox" onClick="return checkForm();" value="Click Here" />

        <br />

<span class="boldenquire2">For 5 ways to get that dream job</span></td>

    </tr>

    <tr align="left">

      <td colspan="2"><br />

          <script language="JavaScript">

var addr = '';

var host = '';

var email = '';

document.write(email);

</script></td>

    </tr>

  </table>

</form>

<?php

}

 

function isEmail($email)

{

return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"

,$email));

}

?>

Let me shed some light on this for you i had a similair issue to this several days ago...

 

 

You need to include this in your mail

 

      $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
      $headers .= $from;

 

But when you call the headers you will need to call them like this,

 

      $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
      $headers .= $from;
      return mail($email, $subject, $body, $headers);

 

Obviously you need to adjust it to work with your code but that is seriously all there is to it

 

 

*EDIT*

 

This should do it for you

 

 

      $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
      $headers .= $from;
      mail($email, $subject, $headers, $autoreply);

 

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.