[英]I need to create a mailto link from PHP code
好的,目前我的 html 表单收集数据并将其发布到一个 php 表单,然后该表单创建并发送电子邮件(以下代码),但是现在我需要该表单来创建一个 mailto 链接,以便我可以将其发送到不同的邮件来自我 iphone6 的帐户,有什么帮助吗???? :)
代码是:
<?php
ini_set( "SMTP", "localhost" );
ini_set( "smtp_port", "25" );
if ( isset( $_POST['caseref'] ) ) {
$email_from = "dave@dave.com";
$to = "dave@dave.com";
$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
}
?>
任何人都可以帮我解决这个问题吗?
电子邮件需要看起来像:
邮箱:davey@dave.com
主题:到达
正文: 事件编号:XXXXXX
到货日期:20/11/2015
到达时间:14:41
工程师:戴夫
工程师注意事项:
正如我们一直在讨论的,您需要在mailto
链接中使用NVP
。 为了尊重您的换行符,您需要使用urlencode()
或rawurlencode()
取决于电子邮件客户端及其尊重编码的方式。
$to = "dave@dave.com";
$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>';
另请注意:我已经从date()
函数中删除了time()
,因为默认情况下使用time()
......指定它是没有必要的。
你能试试这个吗?
<!-- Mailto link needs to go here-->
<?php echo'<a href="mailto:'.$to.'" subject="'.$email_subject.'" body="'.$email_message.'>Send mail</a>';?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.