我正在尝试使用php将用户在HTML表单中插入的用户信息发送到我的电子邮件地址:
$to = "my_email@yahoo.com";
$subject = "Delete Listing";
$email = $_REQUEST['Email'] ;
$message = $_REQUEST['Filename'] && $_REQUEST['reason'];
$headers = "From: $email This File needs to be removed in 48 hrs.Please review it and act accordingly.";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
但我认为我不确定在$ message上使用两个$ _REQUEST ...这就是为什么我在发送电子邮件时收到错误的原因。 (其他部分被执行“我们在发送邮件时遇到错误”)
答案 0 :(得分:0)
如果你使用$message = $_REQUEST['Filename'] && $_REQUEST['reason'];
这会产生一个条件,如果你想连接它们,请使用.
$message = $_REQUEST['Filename'] . $_REQUEST['reason'];
。
答案 1 :(得分:0)
(我认为)问题是:
如果您没有要注册的原始电子邮件,则没有电子邮件服务器会接受该邮件。 电子邮件垃圾邮件保护的一项功能。除非您清楚知道自己在做什么,否则尽量不要使用mail()
函数。
答案 2 :(得分:0)
$message = $_REQUEST['Filename'] && $_REQUEST['reason'];
这里你得到TRUE或FALSE。试试这个
$message = $_REQUEST['Filename'] . ' ' . $_REQUEST['reason'];
答案 3 :(得分:0)
尝试:
$message = "I'm an example.";
mail('my_email@yahoo.com', 'Delete Listing', $message);
如果您收到该消息,则可以使用完整代码。
尝试FastMailBuilder class,易于使用:
(new FastMailBuilder)
->to('my_email@yahoo.com')
->from('New Site', 'no-reply@yourdomain.com')
->subject('Delete Listing')
->text(
"This File needs to be removed in 48 hrs. Please review it and act accordingly."
)->html(
"This File needs to be removed in 48 hrs. <strong>Please review it</strong> and act accordingly."
)->send();
php.ini上的典型配置可能如下所示:
[mail function]
SMTP = smtp.isp.net
sendmail_from = me@isp.net
Configure PHP to Use a Remote SMTP Server for Sending Mail
答案 4 :(得分:0)
确保已配置本地服务器的php.ini文件。如果未正确配置电子邮件设置,则此代码将无用。所以首先检查你的php.ini文件。