【问题标题】:How to add php variables in php Sendinblue emails?如何在 php Sendinblue 电子邮件中添加 php 变量?
【发布时间】:2019-10-20 15:22:13
【问题描述】:

我想使用 Sendinblue 交易电子邮件在 php 中发送电子邮件。 问题是我需要在我的邮件中添加php变量,但是我收到后,php变量并没有变成文本!

这是我收到的:

https://drive.google.com/file/d/1--c84eZcSJpp9icfsNZeXxj048Y-d3f9/view?usp=drivesdk

这是我的 php 代码:

<?php

// Check for empty fields
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['message']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  http_response_code(500);
  exit();
}

$name = strip_tags(htmlspecialchars($_POST['name']));
$email = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));

// Create the email and send the message
$subject = "HMP Reseller - New Message";
$body = "You have received a new message from HMP Reseller contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email\n\nPhone: $phone\n\nMessage:\n$message";

include 'Mailin.php';
$mailin = new Mailin('hosteymega@gmail.com', 'API-KEY');
$mailin->
addTo('hosteymega@gmail.com', 'HosteyMega Hosting')->
setFrom('admin@hosteyme.ga', 'HosteyMega Admin')->
setReplyTo('$email','HMP Reseller Client')->
setSubject('$subject')->
setText('$body')->
setHtml('<h2>$body</h2>');
$res = $mailin->send();
/**
Successful send message will be returned in this format:
{'result' => true, 'message' => 'Email sent'}
*/

?>

有什么办法可以解决吗?

【问题讨论】:

    标签: php email smtp contact-form sendinblue


    【解决方案1】:

    setText('$body') 中,您使用了单引号,而不是双引号,因此 $body 变量不会自动扩展 - 它作为文字字符串传递。您应该使用双引号,或者直接将其作为变量本身传递,因为它应该已经是一个字符串(所以只需使用 setText($body) 而不使用任何引号)。

    此外,为了避免任何可能的转义问题,您可能希望切换到字符串连接来构建主体变量,或者通过将它们包裹在大括号中来使用更明确的变量扩展,如下所示:

    $body = "You have received a new message from HMP Reseller contact form.\n\n"."Here are the details:\n\nName: ${name}\n\nEmail: ${email}\n\nPhone: ${phone}\n\nMessage:\n${message}";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多