我需要从PHP代码创建一个mailto链接

我需要从PHP代码创建一个mailto链接

本文介绍了我需要从PHP代码创建一个mailto链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以目前我的html表单收集数据并将其发布到一个php表单中,然后创建并发送一封电子邮件(下面的代码),但现在我需要表单来创建mailto链接,以便我可以将它发送到从我的iphone6不同的邮件帐户,请任何帮助??? !! :)

代码是:

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

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

$ email_from [email protected];
$ to [email protected];
$ email_subject =抵达:。 $ _POST [ caseref];

函数已死($ error){
//此处错误代码
echo我们非常抱歉,但是在提交的表单中发现错误。 ;
echo这些错误出现在下方。< br />< br />;
echo $错误。 < br />< br />;
echo请回去修正这些错误。< br />< br />;
die();
}

//验证预期数据存在
if(!isset($ _POST ['casreref'])){
#died('抱歉,但是你提交的表格似乎有问题。');
}

$ name = $ _POST ['name']; //必需
$ caseref = $ _POST ['caseref']; //必需
$ notes = $ _POST ['notes']; //必需

$ error_message =;

$ email_message。=事件编号:。 $ caseref。 \\\
;
$ email_message。=到达日期:。日期(d / m / Y);
$ email_message。=\\\
;
$ email_message。=到达时间:。日期(H:i,时间());
$ email_message。=\\\
;
$ email_message。=工程师:。 $名称。 \\\
;
$ email_message。=工程师备注:。 $说明;
$ email_message。=\\\
;
$ email_message。=\\\
;
$ email_message。=\\\
;


$ headers ='From:'。 $ EMAIL_FROM;
mail($ to,$ email_subject,$ email_message,$ headers);
?>
< html>
< title>谢谢!< / title>

Mailto链接需要到这里

<?php
}
?>

任何人都可以帮我解决这个问题吗?



电子邮件需要如下所示:


解决方案

正如我们一直在讨论的那样,您需要在 mailto 链接中使用 NVP 。为了让你的换行符得到遵守,你需要使用 urlencode() rawurlencode(),具体取决于电子邮件客户端和他们如何尊重编码。

  $ to [email protected]; 
$ caseref =123;
$ name =Bob;
$ notes =有些注意事项;
$ email_subject =抵达一些数据;
$ email_message =事件编号:。 $ caseref。 \\\
;
$ email_message。=到达日期:。日期( d / M / Y);
$ email_message。=\\\
;
$ email_message。=到达时间:。日期( H:I);
$ email_message。=\\\
;
$ email_message。=工程师:。 $名称。 \\\
;
$ email_message。=工程师备注:。 $说明;
$ email_message。=\\\
;
$ email_message。=\\\
;
$ email_message。=\\\
;

//回复邮件以链接
echo'< a href =mailto:'。$ to。'?subject ='。urlencode($ email_subject)。'& body ='。urlencode($ email_message)。'>邮件到链接< / a>';

//使用不同的编码回收要链接的邮件
echo'< a href =mailto:'。$ to。'?subject ='。rawurlencode($ email_subject)。 '& body ='。rawurlencode($ email_message)。'> Mail to Link< / a>';

另请注意:我已经删除了 time() date()函数,因为默认使用 time() ...指定它不是必要的。


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 . "\n";
    $email_message .= "Arrival Date:" . date( " d/m/Y " );
    $email_message .= "\n";
    $email_message .= "Arrival Time:" . date( "  H:i  ", time() );
    $email_message .= "\n";
    $email_message .= "Engineer:  " . $name . " \n";
    $email_message .= "Engineers Notes:  " . $notes;
    $email_message .= "\n";
    $email_message .= "\n";
    $email_message .= "\n";


    $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:

解决方案

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 . "\n";
$email_message .= "Arrival Date:" . date("d/m/Y");
$email_message .= "\n";
$email_message .= "Arrival Time:" . date("H:i");
$email_message .= "\n";
$email_message .= "Engineer:  " . $name . " \n";
$email_message .= "Engineers Notes:  " . $notes;
$email_message .= "\n";
$email_message .= "\n";
$email_message .= "\n";

// 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.

这篇关于我需要从PHP代码创建一个mailto链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:37