mjgdunne Posted April 25, 2008 Share Posted April 25, 2008 Hi, i have a php script where an email is sent to a specified email address. I am wondering how i can, or if i can place a link to a site in the email. Here is my php code: <?php session_start(); ini_set( 'display_errors', '1' ); error_reporting ( 2047 ); $fromemail = "postmaster@localhost"; $scripturl = "http://localhost/xampp/mailsend.php"; $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="test"; // Database name $tbl_name="reff"; // Table name // Connect to server and select databse. mysql_connect("$host", "root", "root")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // image and titl and reg sent from form $mymake=$_POST['mymake']; $mymake=$_POST['mymodel']; $myreg=$_POST['myreg']; $myimage=$_POST['myimage']; mysql_select_db("test"); $result = mysql_query("INSERT INTO reff (make, model, registration, imgdata) VALUES ('$_POST[mymake]', '$_POST[mymodel]', '$_POST[myreg]', '$_POST[myimage]')"); $to = "mjgdunne@hotmail.com"; $subject = 'You have being assigned a new case'; $message = 'Go to: http://localhost/rental.html' . 'You have being assigned a new case'; $headers = 'From: postmaster@localhost' . "\r\n" . 'Reply-To: postmaster@localhost' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); header("location:case_assigned.php"); exit(); ?> Thanks ??? Quote Link to comment Share on other sites More sharing options...
ucffool Posted April 25, 2008 Share Posted April 25, 2008 $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; That will allow you to send HTML mail, then simply make your message: $message = 'Go to: <a href="http://localhost/rental.html">http://localhost/rental.html</a>' . 'You have being assigned a new case'; Quote Link to comment Share on other sites More sharing options...
mjgdunne Posted April 25, 2008 Author Share Posted April 25, 2008 Hi, i have added your code, but the email is still not displaying the link correctly, im sending it to my hotmail account, maybe hotmail doesnt allow html emails? ??? <?php session_start(); ini_set( 'display_errors', '1' ); error_reporting ( 2047 ); $fromemail = "postmaster@localhost"; $scripturl = "http://localhost/xampp/mailsend.php"; $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="test"; // Database name $tbl_name="reff"; // Table name // Connect to server and select databse. mysql_connect("$host", "root", "root")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // image and titl and reg sent from form $mymake=$_POST['mymake']; $mymake=$_POST['mymodel']; $myreg=$_POST['myreg']; $myimage=$_POST['myimage']; mysql_select_db("test"); $result = mysql_query("INSERT INTO reff (make, model, registration, imgdata) VALUES ('$_POST[mymake]', '$_POST[mymodel]', '$_POST[myreg]', '$_POST[myimage]')"); $to = "mjgdunne@hotmail.com"; $subject = 'You have being assigned a new case'; // 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"; $message = 'Go to: <a href="http://localhost/rental.html">http://localhost/rental.html</a>' . 'You have being assigned a new case'; $headers = 'From: postmaster@localhost' . "\r\n" . 'Reply-To: postmaster@localhost' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); header("location:case_assigned.php"); exit(); ?> Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 25, 2008 Share Posted April 25, 2008 You were overwriting your $headers variable and eraseing the content type <?php ..... // 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"; $message = 'Go to: <a href="http://localhost/rental.html">http://localhost/rental.html</a>' . 'You have being assigned a new case'; // You were overwriting the $header variable here. // I changed the '=' to '.=' $headers .= 'From: postmaster@localhost' . "\r\n" . 'Reply-To: postmaster@localhost' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); header("location:case_assigned.php"); ..... ?> Quote Link to comment Share on other sites More sharing options...
mjgdunne Posted April 25, 2008 Author Share Posted April 25, 2008 Hi i copied in ur code, maybe i did something wrong because it is now working: <?php session_start(); ini_set( 'display_errors', '1' ); error_reporting ( 2047 ); $fromemail = "postmaster@localhost"; $scripturl = "http://localhost/xampp/mailsend.php"; $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="test"; // Database name $tbl_name="reff"; // Table name // Connect to server and select databse. mysql_connect("$host", "root", "root")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // image and titl and reg sent from form $mymake=$_POST['mymake']; $mymake=$_POST['mymodel']; $myreg=$_POST['myreg']; $myimage=$_POST['myimage']; mysql_select_db("test"); $result = mysql_query("INSERT INTO reff (make, model, registration, imgdata) VALUES ('$_POST[mymake]', '$_POST[mymodel]', '$_POST[myreg]', '$_POST[myimage]')"); $to = "mjgdunne@hotmail.com"; $subject = 'You have being assigned a new case'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = 'Go to: <a href="http://localhost/rental.html">http://localhost/rental.html</a>' . 'You have being assigned a new case'; $headers = 'From: postmaster@localhost' . "\r\n" . 'Reply-To: postmaster@localhost' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); header("location:case_assigned.php"); exit(); ?> Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 25, 2008 Share Posted April 25, 2008 Unfortunately, you didn't copy my code. The line with $headers = 'From: postmaster@localhost' . "\r\n" should be $headers .= 'From: postmaster@localhost' . "\r\n" You are overwriting the $headers variable rather then appending to it. Quote Link to comment Share on other sites More sharing options...
mjgdunne Posted April 25, 2008 Author Share Posted April 25, 2008 Sorry, my head is melted missed copying that. Thanks. Quote Link to comment Share on other sites More sharing options...
ucffool Posted April 25, 2008 Share Posted April 25, 2008 Ah the period, where have you been all my life... concatenation for the win. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.