0

I have this form to mail code where users will receive and email from the form that was submitted.

Here's the whole code:

<?php

error_reporting(E_ALL); ini_set('display_errors', 1);

require_once ('database.php');

if (isset($_POST['send'])) {

$reqname = $_POST['reqname'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$empname = $_POST['empname'];
$position = ($_POST['position']);
$account = $_POST['account'];
$platform = $_POST['platform'];
$processor = $_POST['processor'];
$ram = $_POST['ram'];
$monitor = $_POST['monitor'];
$phone = $_POST['phone'];
$phonetype = $_POST['phonetype'];
$headset = $_POST['headset'];

{
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$insert_query = "INSERT INTO request (reqname, day, month, year, empname, position, account, platform, processor, ram, monitor, phone, phonetype, headset)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

$insert = $database->prepare($insert_query);
$insert->execute(array($reqname, $day, $month, $year, $empname, $position, $account, $platform, $processor, $ram, $monitor, $phone, $phonetype, $headset));

$email_from = "PC Request";//<== update the email address
$email_subject = "PC Request for $account";
$email_body = "Here are the specifications:\n\n".
  "Requested by: $reqname\n".
  "Start Date: $month/$day/$year\n".
  "Employee Name: $empname\n".
  "Position: $position\n".
  "Account: $account\n".
  "Platform: $platform\n".
  "Processor: $processor\n".
  "RAM: $ram\n".
  "Monitor: $monitor\n".
  "Phone: $phone\n".
  "Phone Type: $phonetype\n".
  "Headset: $headset\n".
        "Link: $link\n".
    
$to = "email@email.com";//<== update the email address
$headers = "From: $email_from \r\n";
$link = "www.google.com" \r\n";
mail($to,$email_subject,$email_body, $headers);
//done. redirect to thank-you page.
//header('Location: index.php');

echo "<script>alert('Successfully sent!'); window.location='index.php'</script>";
}
}
?>

So is it possible to add like a link on the email body?

As you can see I've tried creating a variable named link then declaring it to the email body, but obviously it didnt work.

New Edited Code:

<?php

error_reporting(E_ALL); ini_set('display_errors', 1);

require_once ('database.php');

if (isset($_POST['send'])) {

$reqname = $_POST['reqname'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$empname = $_POST['empname'];
$position = ($_POST['position']);
$account = $_POST['account'];
$platform = $_POST['platform'];
$processor = $_POST['processor'];
$ram = $_POST['ram'];
$monitor = $_POST['monitor'];
$phone = $_POST['phone'];
$phonetype = $_POST['phonetype'];
$headset = $_POST['headset'];

{
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$insert_query = "INSERT INTO request (reqname, day, month, year, empname, position, account, platform, processor, ram, monitor, phone, phonetype, headset)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

$insert = $database->prepare($insert_query);
$insert->execute(array($reqname, $day, $month, $year, $empname, $position, $account, $platform, $processor, $ram, $monitor, $phone, $phonetype, $headset));

$email_from = "PC Request";//<== update the email address
$email_subject = "PC Request for $account";
$email_body = "Here are the specifications:\n\n".
  "Requested by: $reqname\n".
  "Start Date: $month/$day/$year\n".
  "Employee Name: $empname\n".
  "Position: $position\n".
  "Account: $account\n".
  "Platform: $platform\n".
  "Processor: $processor\n".
  "RAM: $ram\n".
  "Monitor: $monitor\n".
  "Phone: $phone\n".
  "Phone Type: $phonetype\n".
  "Headset: $headset\n".
  <a href='https://google.com'>Google</a>
    
$to = "email@email.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$email_subject,$email_body, $headers);
//done. redirect to thank-you page.
//header('Location: index.php');

echo "<script>alert('Successfully sent!'); window.location='index.php'</script>";
}
}
?>
Wade Boar
  • 15
  • 6
  • 1
    You created the variable *after* you tried to use it. You also created a syntax error, so this won't execute at all and you'll see an error in your PHP logs... – David Jan 25 '19 at 20:50
  • `\r\n` needs to be inside the quotes. – Barmar Jan 25 '19 at 20:51

1 Answers1

0

Just use HTML to create your link:

<a href='https://google.com'>Google</a>

and put it in the body of your mail

And make sure you put the correct content-type in your headers:

$headers .= "Content-Type: text/html;";
Laurens
  • 2,596
  • 11
  • 21