我会在HTML页面上创建一个简单的表单,然后将action属性指向.php文件来测试这个php脚本吗?我已经创建了PHP文件,只是不知道如何发送它。
<?php
$recipients = array('name@domain.com','name@domain.com',
'name@domain.com',
'name@domain.com',
); // i will be inserting the test email here
// Assigning data from the $_POST array to variables
$name = $_POST['sender_name'];
$mail_from = $_POST['sender_email'];
$mail_to = $_POST[$recipients];
$message = $_POST['sender_message'];
// Construct email subject
$subject = 'College Newsletter: ' . $name;
// Construct email body
$body_message = 'From: ' . $name . "'r'n";
$body_message .= 'E-mail: ' . $mail_from . "'r'n";
$body_message .= 'Message: ' . $message;
// Construct email headers
$headers = 'From: ' . $name . "'r'n";
$headers .= 'Reply-To: ' . $mail_from . "'r'n";
$mail_sent = mail(implode(',',$mail_to), $subject, $body_message, $headers);
?>
服务器似乎不喜欢我的内爆方法。(见上图)我一直收到错误:警告:内爆()[函数.内爆]:传入的参数无效我把PHP改成了这个:
<?php
$to = array('name@domain.com','name@yahoo.com');
// specify your email here
// Assigning data from the $_POST array to variables
$name = $_POST['name'];
$mail_from = $_POST['mail'];
$message = $_POST['message'];
// Construct email subject
$subject = 'Breaking News: ' . $name;
// Construct email body
$body_message = 'From: ' . $name . "'r'n";
$body_message .= 'E-mail: ' . $mail_from . "'r'n";
$body_message .= 'Message: ' . $message;
// Construct email headers
$headers = 'From: ' . $name . "'r'n";
$headers .= 'Reply-To: ' . $mail_from . "'r'n";
mail($to, $name, $mail_from, $message, $headers);
?>
现在我得到错误:警告:mail()要求参数1为字符串,数组在第70行的bulk_mailer_test.php中给定任何人-干杯,-qs
您的问题在于此代码
<?php
$recipients = array('name@domain.com','name@domain.com',
'name@domain.com',
'name@domain.com',
); // i will be inserting the test email here
$mail_to = $_POST[$recipients];
$mail_sent = mail(implode(',',$mail_to)...
内爆()想要一个数组。您传递的值可能为空。
删除此$mail_to = $_POST[$recipients];
并只使用mail(implode(',',$recipients)
$_POST是一个超级全局,用于从提交的表单中收集数据。如果您已在数组中列出收件人地址。。那么就不需要了。如果你想从表单中收集多封电子邮件,那么就这样做。。。
$recipients = array($_POST['email_1'], $_POST['email_2'], $_POST['email_3'], $_POST['email_4'],
);