如何在php Sendinblue电子邮件中添加php变量?

时间:2019-06-05 06:06:03

标签: php email smtp contact-form sendinblue

我想使用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'}
*/

?>

有什么办法解决吗?

1 个答案:

答案 0 :(得分:0)

paddingBottom中,您使用单引号而不是双引号,因此{ "name": "mychannel", "description": "Network on IBP v2", "version": "1.0.0", "client": { "organization": "org1msp" }, "organizations": { "org1msp": { "mspid": "org1msp", "peers": [ "173.193.78.236:32758" ], "certificateAuthorities": [ "173.193.78.236:32153" ] } }, "orderers": { "173.193.78.236:30360": { "url": "grpcs://173.193.78.236:30360", "tlsCACerts": { "pem": "-----BEGIN CERTIFICATE-----\nMIICKDCCAc6gAwIBAgIULF/WNZP4tLQb1j1WDEPiHUuKo9owCgYIKoZIzj0EAwIw\nZTELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK\nEwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRYwFAYDVQQDEw1PcmRlcmVy\nQ0EtdGxzMB4XDTE5MDYwNTA1NDUwMFoXDTM0MDYwMTA1NDUwMFowZTELMAkGA1UE\nBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQKEwtIeXBlcmxl\nZGdlcjEPMA0GA1UECxMGRmFicmljMRYwFAYDVQQDEw1PcmRlcmVyQ0EtdGxzMFkw\nEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEEV4XYJmpL+70hlChQRmoEDic2843FLje\ntP6Jc5gaQFlj+hObYrAPAmXnZT9TSFqEz3v1cQIXmxqsi63SPOY4LaNcMFowDgYD\nVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYEFKPw9Hvm\nCMSEGJ7k81u1XkgcsL2jMBUGA1UdEQQOMAyHBK3BT+yHBAovepMwCgYIKoZIzj0E\nAwIDSAAwRQIhAJj1YK2QptBVbaqX6FcVUyKzC/RQ+g+P/xLXr1MJCoeIAiB+NFii\nGIkmI2zmPvspkui+feBwMdBAl8H+Qeb1VsLZMQ==\n-----END CERTIFICATE-----\n" } } }, "peers": { "173.193.79.236:32758": { "url": "grpcs://173.193.79.236:32758", "tlsCACerts": { "pem": "-----BEGIN CERTIFICATE-----\nMIICITCCAcigAwIBAgIURAV0BZcyHwWpDXAWcOdU4jRfQW4wCgYIKoZIzj0EAwIw\nYjELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK\nEwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRMwEQYDVQQDEwpPcmcxQ0Et\ndGxzMB4XDTE5MDYwNTA1MzcwMFoXDTM0MDYwMTA1MzcwMFowYjELMAkGA1UEBhMC\nVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQKEwtIeXBlcmxlZGdl\ncjEPMA0GA1UECxMGRmFicmljMRMwEQYDVQQDEwpPcmcxQ0EtdGxzMFkwEwYHKoZI\nzj0CAQYIKoZIzj0DAQcDQgAEnIYUnQDBa0fOeQ+3Z9QN8Af21z6l8l8MxXPw3OPP\n3Ssajl6bigEmPpfWlq0aj3L3p9OFlS5GJgEegXb5v2qtn6NcMFowDgYDVR0PAQH/\nBAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYEFMu/9gjnJroF8WI5\npCzFkBjQ+XRdMBUGA1UdEQQOMAyHBK3BT+yHBAovepMwCgYIKoZIzj0EAwIDRwAw\nRAIgeLh+7v0DduBFnaB4L31UD+X4l81QjB+eY+hLpArwagECIA2TbthMiV2sQnDF\nQLIZo/iz1fXBVCl72QUxlStHRXY/\n-----END CERTIFICATE-----\n" }, "grpcOptions": { "ssl-target-name-override": "173.193.78.236" } } }, "certificateAuthorities": { "173.193.78.236:32153": { "url": "https://173.193.78.236:32153", "caName": "ca", "tlsCACerts": { "pem": "-----BEGIN CERTIFICATE-----\r\nMIICeTCCAeKgAwIBAgIJEk5d1AerUcGfMA0GCSqGSIb3DQEBBQUAMHQxFzAVBgNV\r\nBAMTDjE3My4xOTMuNzkuMjM2MQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGgg\r\nQ2Fyb2xpbmExEDAOBgNVBAcTB1JhbGVpZ2gxDDAKBgNVBAoTA0lCTTETMBEGA1UE\r\nCxMKQmxvY2tjaGFpbjAeFw0xOTA2MDUwNTQxNDBaFw0yMDA2MDQwNTQxNDBaMHQx\r\nFzAVBgNVBAMTDjE3My4xOTMuNzkuMjM2MQswCQYDVQQGEwJVUzEXMBUGA1UECBMO\r\nTm9ydGggQ2Fyb2xpbmExEDAOBgNVBAcTB1JhbGVpZ2gxDDAKBgNVBAoTA0lCTTET\r\nMBEGA1UECxMKQmxvY2tjaGFpbjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA\r\nk4OR+iK7u6c34+KzDNyZXCTPhr3tjl/qTmayU5IVXKc/fHOoWkyccsl2+oUa29cH\r\nEd4z12Ugv36d7Jh0RmrdAHZZK87iXEuFHL2DZe9hXxlQ4FenaHR6NACK+MxDtxy1\r\nNRiL+2Uxp86jBJZGUiydscKDl0xeRQpFygmHyB64pXcCAwEAAaMTMBEwDwYDVR0R\r\nBAgwBocErcFP7DANBgkqhkiG9w0BAQUFAAOBgQCKUDIAMUMoIwbBxmsxdqSjGOkA\r\ni9fywxFc9L1JzrO/KzFDnmzP1SWwa6dJBpyicY5K37bdM4nFlQUIaXjiPHF250Qq\r\ntyb/DzNw+81ouEsegKZWlK0DPmSEY28QD2eMcVwW3Oo0QviY4JmS9RzqKvOp4IA5\r\nl1vKEo4aiETiXS9sig==\r\n-----END CERTIFICATE-----\r\n" } } } } 变量不会自动展开-它将其作为文字字符串传递。您应该使用双引号,或者只是将其作为变量本身传递,因为它应该已经是字符串(因此,只需使用setText('$body')而不带任何引号)即可。

此外,为了避免任何可能的转义问题,您可能希望切换到字符串连接以构建body变量,或者通过将它们用大括号括起来来使用更明确的变量扩展,例如:

$body