Jump to content

[SOLVED] link in email


mjgdunne

Recommended Posts

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 = "[email protected]";
$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  ???

Link to comment
https://forums.phpfreaks.com/topic/102877-solved-link-in-email/
Share on other sites

$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';

Link to comment
https://forums.phpfreaks.com/topic/102877-solved-link-in-email/#findComment-527269
Share on other sites

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 = "[email protected]";
$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();
?>

Link to comment
https://forums.phpfreaks.com/topic/102877-solved-link-in-email/#findComment-527291
Share on other sites

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");

.....

?>

Link to comment
https://forums.phpfreaks.com/topic/102877-solved-link-in-email/#findComment-527295
Share on other sites

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 = "[email protected]";
$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();
?>

Link to comment
https://forums.phpfreaks.com/topic/102877-solved-link-in-email/#findComment-527309
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.