【问题标题】:Email form fields array电子邮件表单字段数组
【发布时间】:2012-05-27 02:24:22
【问题描述】:

我可以用电子邮件表单字段数组创建一个数组。

 if(isset($_POST['submit'])){
        $content=array(
        $name=$this->strip_tags($_POST['name']),
        $email=$this->strip_tags($_POST['email']),
        $phone=$this->strip_tags($_POST['phone']),
        $address=$this->strip_tags($_POST['address']),
        $city=$this->strip_tags($_POST['city']),
        $subject=$this->strip_tags($_POST['subject']),
        $message=$this->strip_tags($_POST['message'])
        );

然后使用邮件功能发送。

提前谢谢你

【问题讨论】:

  • 创建数组的正确语法使用 array('key' => $value) ,而不是您在此处使用的 array($key = $value) (有效,但不会产生您可能期望的结果)。为什么要在一个数组中给mail()呢?然后,您需要将每个值拉回以将其显示在您的消息正文中。

标签: php arrays email


【解决方案1】:

你可以这样做,这要容易得多:

if(isset($_POST['submit'])) {

$to = "someone@example.com"; // send email to
$from = "Your Name <you@example.com>"; // send email from
$subject = "Form submitted"; // email subject
$body = "The form has been submitted!

Here's the form data that was submitted.

Name: ".$_POST['name']."
Email: ".$_POST['email']."
Phone: ".$_POST['phone']."
Address: ".$_POST['address']."
City: ".$_POST['city']."
Subject: ".$_POST['subject']."

Message:

".$_POST['message']."

Some other text under the form data here...";

$email = mail($to, $subject, $body, "From: $from");

if($email) { // you don't actually need this, it's just to make sure it sends :)
echo "Email sent successfully";
}

}

这将发送一封包含已提交表单数据的电子邮件。

我希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2014-05-22
    • 2018-02-23
    • 1970-01-01
    • 2023-02-21
    相关资源
    最近更新 更多