dongqin8652 2019-01-25 20:46
浏览 68

在由PHP代码执行的电子邮件上添加链接[重复]

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:

".
        "Requested by: $reqname
".
        "Start Date: $month/$day/$year
".
        "Employee Name: $empname
".
        "Position: $position
".
        "Account: $account
".
        "Platform: $platform
".
        "Processor: $processor
".
        "RAM: $ram
".
        "Monitor: $monitor
".
        "Phone: $phone
".
        "Phone Type: $phonetype
".
        "Headset: $headset
".
        "Link: $link
".
    
$to = "email@email.com";//<== update the email address
$headers = "From: $email_from 
";
$link = "www.google.com" 
";
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:

".
        "Requested by: $reqname
".
        "Start Date: $month/$day/$year
".
        "Employee Name: $empname
".
        "Position: $position
".
        "Account: $account
".
        "Platform: $platform
".
        "Processor: $processor
".
        "RAM: $ram
".
        "Monitor: $monitor
".
        "Phone: $phone
".
        "Phone Type: $phonetype
".
        "Headset: $headset
".
        <a href='https://google.com'>Google</a>
    
$to = "email@email.com";//<== update the email address
$headers = "From: $email_from 
";
$headers = "MIME-Version: 1.0" . "
";
$headers .= "Content-type:text/html;charset=UTF-8" . "
";
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>";
}
}
?>

</div>
  • 写回答

1条回答 默认 最新

  • donglingyi4679 2019-01-25 20:49
    关注

    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;";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器