在我的网站上,我有两个发送电子邮件的表格。不需要附件的一个会被正确发送,但另一个只有附件的不会被发送。我正在使用SMTP config whit Postman SMTP插件。
move_uploaded_file($_FILES["cv"]["tmp_name"],WP_CONTENT_DIR .\'/uploads/CV/\'.basename($_FILES[\'cv\'][\'name\']));
move_uploaded_file($_FILES["lm"]["tmp_name"],WP_CONTENT_DIR .\'/uploads/lm/\'.basename($_FILES[\'lm\'][\'name\']));
$attachments = array(
WP_CONTENT_DIR ."/uploads/CV/".$_FILES["cv"]["name"],
WP_CONTENT_DIR ."/uploads/lm/".$_FILES["lm"]["name"]
);
这是我用来存储和访问附件的代码,simpli使用wp\\u mail函数发送它,如下所示:
$sent=wp_mail($s, $subject, $message, $headers,$attachments);
在另一个表单上,我使用相同的代码,只是去掉了$attachments变量。没有附件的一个会被发送,但另一个不会。有人能帮我解决我的问题吗?
SO网友:rudtek
我还将尝试使用下面的方式添加到数组中。(参见我的示例)尝试使用这两个文件的实际位置作为测试,然后插入php。我已经列出了3种不同的尝试选项,但您当然应该使用站点上这些文件的实际url/
<?php
$attachments = array(); //may or may not be needed.
$att1 = WP_CONTENT_DIR . \'/uploads/my-1st-attachemnt.zip\';
$att2 = WP_CONTENT_DIR . \'/uploads/my-second-attachment.zip\';
$attachments[] =$att1; //try these as working solution
$attachments[] =$att2; //try these as working solution
$attachments[] = \'http://www.example.com/wp-content/uploads/my-1st-attachemnt.zip\'; //try this 2nd
$attachments[] = \'/wp-content/uploads/my-second-attachment.zip\'; //try this last
$to="[email protected]";
$subject="Online: multiple attachment demo through wp_mail of wordpress";
$message="This is testing";
$headers = \'From: NAPSWI online <[email protected]>\';
get_header();
if( wp_mail( $to, $subject, $message, $headers, $attachments) ) {
// the message was sent...
echo \'The test message was sent. Check your email inbox.\';
} else {
// the message was not sent...
echo \'The message was not sent!\';
}
?>