电子邮件表单字段数组

时间:2012-05-26 18:12:53

标签: php arrays email

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

 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'])
        );

然后使用邮件功能发送它。

提前谢谢

1 个答案:

答案 0 :(得分:2)

你可以这样做,这更容易:

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";
}

}

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

我希望这有帮助!