Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm not receiving emails when using the following function. Is there another method that works or that I can test?

<?php 
$data = ob_get_clean();

require_once(dirname(__FILE__).'/make-pdf.php');
require_once(dirname(__FILE__).'/attach-mail.php');

$pdf = make_pdf($data);
$filename = 'confirmation_'.date('Ymd_his').'.pdf';

$to = $_POST['admin_email'];
$from = 'my@email.com';
$subject = "Enquiry";

mail_attachment($filename, $pdf, $to, $from, $subject, $message);
echo $data;

} ?>

attach-mail.php

<?php
function mail_attachment($filename, $data, $mailto, $from_mail, $subject, $message) {
    $file_size = strlen($data);
    $data = chunk_split(base64_encode($data));
    $uid = md5(uniqid(time()));
    $header = "From: ".$from_mail."\r\n";
    $header .= 'Cc: my-other@email.com' . "\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/html; charset=iso-8859-1\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $message."\r\n\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
    $header .= $data."\r\n\r\n";
    $header .= "--".$uid."--";
    mail($mailto, $subject, "", $header);
}
?>
share|improve this question
    
There is nothing in your example to suggest you're using WordPress. –  Wyck Dec 4 '12 at 6:02
    
Well, I am using Wordpress just the mail function rather than wp_mail function. –  Dave Dec 4 '12 at 6:08
1  
This is a general PHP question, you just use WordPress as a framework for running your PHP code. Did you consider using wp_mail? –  fischi Dec 4 '12 at 6:14
    
Yup, wp_mail is even worse unfortunately :( Looks like mail is being blocked by a spam filter. Could be the issue and solvable. –  Dave Dec 4 '12 at 6:21
add comment

1 Answer

Installing Swift SMTP plugin --http://www.shiftthis.net/wordpress-swift-smtp-plugin/ should fix the problem. For few people this problem got fixed in wordpress-2.2

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.