dongzongzhi6953 2015-02-24 15:52
浏览 39

已发送邮件但未在wp_mail()中收到附件

I am new in wordpress. I am trying to send a mail with an attachment. But every time the mail is being sent but the attachment is not. I searched almost all the post related to this topic here but all the solutions failed for me. I checked the path a lot of times and found that it is correct from 'uploads' folder. Please help me. This is my code,

<?php

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

$to = $_POST['email'];
$pdf = $_POST['pdf'];

$subject = "Presidency Alumni Annual Report";
$message = "Please download the attachment.";
$headers = 'From: Presidency Alumni Association Calcutta <noreply@presidencyalumni.com>' . "
";

if($pdf == 'a'){

$attachments = array(WP_CONTENT_DIR . 'uploads/2015/01/Coffee-Mug-Banner.jpg');
}
else if($pdf == 'b'){

$attachments = array(WP_CONTENT_DIR . 'uploads/2014/08/Alumni-Autumn-Annual-2014.pdf');
 }
else{

$attachments = array(WP_CONTENT_DIR . 'uploads/2014/08/Autumn-Annual-2012.pdf');
}

wp_mail($to, $subject, $message, $headers, $attachments);

print '<script type="text/javascript">';
print 'alert("Your Mail has been sent successfully")';
print '</script>';  
}
?>
  • 写回答

1条回答 默认 最新

  • dpleylxzx47207117 2015-02-24 16:00
    关注

    The most probable reason this to happen is if the condition if($pdf == 'a') {...} else if ($pdf == 'b') {...}) is not true. Check to see if this variable pdf is set properly in your post HTML form.

    Also make sure that the constant WP_CONTENT_DIR contains something, i.e. is not empty string, because otherwise your path to the attachments will be invalid, i.e. it is better to access your uploads directory like this:

    <?php $upload_dir = wp_upload_dir(); ?>

    The $upload_dir now contains something like the following (if successful):

    Array (
        [path] => C:\path\to\wordpress\wp-content\uploads\2010\05
        [url] => http://example.com/wp-content/uploads/2010/05
        [subdir] => /2010/05
        [basedir] => C:\path\to\wordpress\wp-content\uploads
        [baseurl] => http://example.com/wp-content/uploads
        [error] =>
    )
    

    Then, modify your code:

    $attachments = array($upload_dir['url'] . '/2014/08/Autumn-Annual-2012.pdf');

    See the documentation.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀