Jump to content

[SOLVED] PHP Mailer


savagenoob

Recommended Posts

I have an issue with PHP Mailer, since I use Godaddy for webhosting, I can only relay 1000 emails and I cannot get it to send files. I have files and pics stored in a database that customers can upload/download. I was wondering if it was possible to use a different email account, that the user specifys via smtp settings/password, to relay emails. And, is it possible to use php/phpmailer to download a file from a database, attach it, and send using phpmailer.

Link to comment
https://forums.phpfreaks.com/topic/159196-solved-php-mailer/
Share on other sites

Heres a basic example

 

<?php
require_once('../class.phpmailer.php');
require_once('../class.pop3.php'); // required for POP before SMTP

$pop = new POP3();
$pop->Authorise('pop3.yourdomain.com', 110, 30, 'username', 'password', 1);

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

$mail->IsSMTP();

try {
  $mail->SMTPDebug = 2;
  $mail->Host     = 'pop3.yourdomain.com';
  $mail->AddReplyTo('[email protected]', 'First Last');
  $mail->AddAddress('[email protected]', 'John Doe');
  $mail->SetFrom('[email protected]', 'First Last');
  $mail->AddReplyTo('[email protected]', 'First Last');
  $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  $mail->MsgHTML(file_get_contents('contents.html'));
  $mail->AddAttachment('images/phpmailer.gif');      // attachment
  $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
  $mail->Send();
  echo "Message Sent OK\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}
?>

 

But your need to get the data from the database and rebuild the example or update phpmailer to allow raw data files

Link to comment
https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-839575
Share on other sites

Hm, I am getting this error now

 

Array

(

    [error] => Connecting to the POP3 server raised a PHP warning:

    [errno] => 2

    [errstr] => fsockopen() [function.fsockopen]: unable to connect to smtp.bizmail.yahoo.com:110 (Connection timed out)

)

Failed to connect to server smtp.bizmail.yahoo.com on port 110110Connection timed out

 

any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-839654
Share on other sites

If that line isn't in there, you probably have a custom php install. In that case you need to add the line to php.ini and download the sockets dll.

 

In order to get the php_sockets.dll:

- Download the regular php zip file from http://www.php.net/downloads.php

- Find the dll in the ext directory

- Extract the php_sockets.dll to the ext directory of your install

(probably at c:\program files\PHP\ext)

 

check phpinfo(); to test its installed correctly

Link to comment
https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-840311
Share on other sites

OK, I actually got this to work via SMTP. Now I cant figure out how to attach a file that is stored in a database. Here is my lengthy code, sorry but necessary to see how it works... It is sending the email but not the attachment.

 

if (isset($_POST['SUBMIT'])) {
    require ('class.phpmailer.php');
    require ('class.smtp.php');
    $toemail1 = $_POST['toEml'];
    $toemail2 = $_POST['toEml2'];
    $fromemail = $_POST['fromEml'];
    $fromname = $_POST['fromName'];
    $reply = $_POST['reply'];
    $subject = $_POST['subj'];
    $body = $_POST['body'];
    $attach1 = $_POST['attach'];
    $attachment = @mysql_query("SELECT content, type, name, size FROM upload WHERE id= '$attach1'") or
        die(mysql_error());
    $data = @mysql_result($result, 0, "content");
    $name = @mysql_result($result, 0, "name");
    $size = @mysql_result($result, 0, "size");
    $type = @mysql_result($result, 0, "type");
    header("Content-type: $type");
    header("Content-length: $size");
    header("Content-Disposition: attachment; filename=$name");
    header("Content-Description: PHP Generated Data");

    $memberid = $_SESSION['SESS_MEMBER_ID'];

    $emailset = mysql_query("SELECT * FROM email WHERE userid = '$memberid' ORDER BY ID DESC LIMIT 1") or
        die(mysql_error());
    $emailout = mysql_fetch_array($emailset);

    $mail = new PHPMailer();

    $mail->Host = $emailout['outgoing']; // specify main and backup server
    $mail->Username = $emailout['user']; // SMTP username
    $mail->Password = $emailout['pass']; // SMTP password
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Port = $emailout['port'];
    $mail->From = $fromemail;
    $mail->FromName = $fromname;
    $mail->AddAddress($toemail1);
    $mail->AddAddress($toemail2); // name is optional
    $mail->AddReplyTo($reply);

    $mail->WordWrap = 50; // set word wrap to 50 characters
    $mail->AddAttachment($data); // add attachments    
    $mail->IsHTML(true); // set email format to HTML

    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AltBody = $body;

    if (!$mail->Send()) {
        echo "Message could not be sent. <p>";
        exit;
    }

    echo "Message has been sent";
}

I know I didnt sanitize user inputted data, I will get there, just wanna get this working first :)

Link to comment
https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-843910
Share on other sites

OK, I actually found out that PHP Mailer already supports data sent via string/database...

for anyone else that needs to do this.. here is the line you need... SOLVED!

 

$mail->AddStringAttachment($string,$filename,$encoding,$type); 

PS... for encoding... dont use binary, use base64.

Also, along my journey, found a kick ass PHP Mailer tutorial that at one point was featured on this site (which is awesome might I add) but no longer shows up as far as I can tell...

http://www.askapache.com/php/phpfreaks-eric-rosebrocks-phpmailer-tutorial.html

Link to comment
https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-844576
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.