Search code examples
phphtmlformsemailmailto

Can I set recipient of mailto to a php string?


is it possible to set my mailto recipient to the $email string? I have a reservation form on my website and i want to have 2 buttons(Accept/Decline) in the mail that i get from it. The buttons should automatically open a new email windows with the set body and the recipient email from the form. My problem is that i cant get the email from the form into the mailto button.

some help would be nice :)

 <?php
include dirname(dirname(__FILE__)).'/mail.php';

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;


if($post){
    $name = stripslashes($_POST['name']);
    $email = trim($_POST['email']);
    $phone = stripslashes($_POST['phone']);
    $amount = stripslashes($_POST['amount']);
    $date = stripslashes($_POST['date']);
    $time = stripslashes($_POST['time']);

    $message .= "Telefonnummer: ".$phone."\n<br />"."Personen: ".$amount."\n<br />"."Datum: ".$date."\n<br />"."Uhrzeit: ".$time."\n<br />";
    $message .= '<html><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><table border="0" cellspacing="0" cellpadding="0"><tr><td><a href="mailto:<?php $email?>?Subject=Reservierung 73BB&Body=Hiermit bestaetigen wir Ihre Reservierung in der ...." target="_blank" style="font-size: 16px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; background-color: #EB7035; border-top: 12px solid #EB7035; border-bottom: 12px solid #EB7035; border-right: 18px solid #EB7035; border-left: 18px solid #EB7035; display: inline-block;">Annehmen &rarr;</a></td></tr></table></td></tr></table></html>';
    $message .= '<html><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><table border="0" cellspacing="0" cellpadding="0"><tr><td><a href="mailto:<?php $email?>?Subject=Reservierung 73&Body=Leider müssen wir Ihre Reservierung ablehnen da wir schon ausgebucht sind" target="_blank" style="font-size: 16px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; background-color: #EB7035; border-top: 12px solid #EB7035; border-bottom: 12px solid #EB7035; border-right: 28px solid #EB7035; border-left: 18px solid #EB7035; display: inline-block;">Ablehnen &rarr;</a></td></tr></table></td></tr></table></html>';

$headers = "From: $name\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    $mail = mail('[email protected]', 'Reservierung', $message, $headers);

    if($mail){
        echo 'Ihre Reservierung wurde erfolgreich abgeschickt. Sie erhalten in kürze eine Bestätigung';
    }

}
?>

Solution

  • You do not have to open php tags again. Just add slashes and concatenate your variable.

    $message .= '<html>...<a href="mailto:' . $email . '?...</html>';