Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

html - I need to create a mailto link from PHP code

Ok, so at the moment my html form gathers data and posts it to a php form which then creates and sends an email (following code), however now I need the form to create a mailto link so I can send it to a different mail account from my iphone6, any help please???!! :)

The code is:

<?php
ini_set( "SMTP", "localhost" );
ini_set( "smtp_port", "25" );

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

    $email_from = "[email protected]";
    $to = "[email protected]";
    $email_subject = "Arrival:  " . $_POST['caseref'];

    function died( $error ) {
        // error code here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error . "<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if ( !isset( $_POST['casreref'] ) ) {
        #died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $name = $_POST['name']; // required
    $caseref = $_POST['caseref']; // required
    $notes = $_POST['notes']; // required

    $error_message = "";

    $email_message .= "Incident Number: " . $caseref . "
";
    $email_message .= "Arrival Date:" . date( " d/m/Y " );
    $email_message .= "
";
    $email_message .= "Arrival Time:" . date( "  H:i  ", time() );
    $email_message .= "
";
    $email_message .= "Engineer:  " . $name . " 
";
    $email_message .= "Engineers Notes:  " . $notes;
    $email_message .= "
";
    $email_message .= "
";
    $email_message .= "
";


    $headers = 'From: ' . $email_from;
    mail( $to, $email_subject, $email_message, $headers );
    ?>
    <!-- include your own success html here -->
    <html>
        <title>Thank you!</title>

        Mailto link needs to go here

<?php
}
?>

Can anyone help me out with this at all please?

The email needs to look like:

mailto: [email protected]

subject: Arrival

body: Incident Number:XXXXXX

Arrival Date: 20/11/2015

Arrival Time: 14:41

Engineer: Dave

Engineers Notes:

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As we've been discussing, you need to use NVP in the mailto link. For your newline breaks to be respected, you need to use urlencode() or rawurlencode() depending on email clients and how they respect encoding.

$to = "[email protected]";
$caseref = "123";
$name = "Bob";
$notes = "Some notes";
$email_subject = "Arrival some data";
$email_message = "Incident Number: " . $caseref . "
";
$email_message .= "Arrival Date:" . date("d/m/Y");
$email_message .= "
";
$email_message .= "Arrival Time:" . date("H:i");
$email_message .= "
";
$email_message .= "Engineer:  " . $name . " 
";
$email_message .= "Engineers Notes:  " . $notes;
$email_message .= "
";
$email_message .= "
";
$email_message .= "
";

// Echo the mail to link
echo '<a href="mailto:'.$to.'?subject='.urlencode($email_subject).'&body='.urlencode($email_message).'">Mail to Link</a>';

// Echo the mail to link using the different encoding
echo '<a href="mailto:'.$to.'?subject='.rawurlencode($email_subject).'&body='.rawurlencode($email_message).'">Mail to Link</a>';

Also note: I've removed the time() from your date() function since by default time() is used...specifying it is not necessary.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...