Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPMailer not always delivering #438

Closed
cinder09 opened this issue Jun 15, 2015 · 4 comments
Closed

PHPMailer not always delivering #438

cinder09 opened this issue Jun 15, 2015 · 4 comments

Comments

@cinder09
Copy link

Hey, I'm having problems with the php mailer.

I'm having a little webapp, where the user uploads images. These images then are embeded to an email and (together with a pdf) put inside a zip and attached to the email.
This email then is sent to the user and the host of the site.

The email is sent automatically in two ways: one way the user klicks a link where the php-script is fired.
The second way is via paypal - after purchase the user is redirected to the php-page which automatically sends the email.
BUT, the emails aren't delivered all the time.
This is a huge problem especially after the paypal-purchase, since the email is essential for further steps and the customer already paid.

When I test it from my computer, it mostly works (is there any connection since it's the same computer...I don't know)

Here's the code

[...]generate pdf, zip file, set content for email and so on[...]

$mail = new PHPMailer();

$mail->CharSet = 'utf-8';
$mail->From = '[email protected]';    
$mail->FromName = "Testname";  
$mail->AddReplyTo("[email protected]", "Testname"); 

$mail->addAddress('[email protected]', 'Test Name');
$mail->addAddress($_SESSION["CustomerMail"], $_SESSION["CustomerName"]);

$mail->Body = $content;

$mail->WordWrap = 50;    
$mail->IsHTML(true);

$mail->Subject = "EMAIL SUBJECT";


/*———————————————————————————*/
/*——————— ADD IMAGES ————————*/
/*———————————————————————————*/

for($i = 0; $i< $_SESSION["productCount"];$i++)
{
    $currImg = base64_encode(file_get_contents($imagenames[$i]));
    $src = 'data: '.mime_content_type($imagenames[$i]).';base64,'.$currImg;

    $mail->AddEmbeddedImage($imagenames[$i], 'imgname'.$i, 'imgname'.$i);
}


$mail->AddAttachment("../FOLDER/".$_SESSION['foldername']."/zipname.zip");

if(!$mail->Send())
{
   echo "Die Email konnte nicht versendet werden, wenden Sie sich bitte an <a href='mailto:[email protected]'>[email protected]</a>";
   echo "Mailer Fehler: " . $mail->ErrorInfo;
   exit;
}
else
{

[...]Delete session,zip, files, and so on[...]

I really hope you can help me

@Synchro
Copy link
Member

Synchro commented Jun 15, 2015

Why are you doing all that base64_encode etc with the images? You don't seem to be using $src anywhere. Are you sure that $content contains all the matching identifiers you're using in addEmbeddImage? If it's not meant to match, you should be using the simpler addAttachment instead.

You don't need to set WordWrap - that will be a leftover from an old example script.

As far as delivery goes, you're sending via your local mail server, so you need to look in your mail server log to see what is happening as that's outside PHPMailer's control.

@cinder09
Copy link
Author

for($i = 0; $i< $_SESSION["productCount"];$i++)
{
    $currImg = base64_encode(file_get_contents($imagenames[$i]));
    $src = 'data: '.mime_content_type($imagenames[$i]).';base64,'.$currImg;


    $content .=
    '<tr>
    <td><table width="600" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="3" style="font-size:18px; font-weight: normal; color:#070000; text-transform: uppercase;">image '.($i+1).'</td>
    </tr>
    <tr>
    <td colspan="3">&nbsp;</td>
    </tr>
    <tr>
    <td width="146" rowspan="4" valign="top" style="padding:0"><img src="cid:imgname'.$i.'" alt="imgname'.$i.'" width="146"></td>
    <td width="40">&nbsp;</td>
    <td style="color:#000; font-size:15px; height: 146px;">'
    </td>
    </tr>
    <tr>
    <td width="40">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td width="40">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td valign="top">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table></td>
    </tr>';

}

I'm embeding the images like so. It seems like I'm redeclaring the $src inside the loop.
Anyway the images are embeded correctly when the email is delivered

I guess using smtp won't solve the issue.
The emails are pretty big too.

@Synchro
Copy link
Member

Synchro commented Jun 15, 2015

OK, so it looks like you can get rid of $currImg and $src then.

So what does your mail server say?

@cinder09
Copy link
Author

sadly I don't have access to a mail log, but I'll try it with smtp, maybe this will solve the problem

@Synchro Synchro closed this as completed Jul 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants