savagenoob Posted May 22, 2009 Share Posted May 22, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/ Share on other sites More sharing options...
MadTechie Posted May 22, 2009 Share Posted May 22, 2009 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('name@yourdomain.com', 'First Last'); $mail->AddAddress('whoto@otherdomain.com', 'John Doe'); $mail->SetFrom('name@yourdomain.com', 'First Last'); $mail->AddReplyTo('name@yourdomain.com', '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 Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-839575 Share on other sites More sharing options...
savagenoob Posted May 22, 2009 Author Share Posted May 22, 2009 SWEET! So just use pop3... that is awesome. I can figure out how to download and attach file I think, I will mess with it and see how it comes out. Thanks a million. Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-839588 Share on other sites More sharing options...
savagenoob Posted May 22, 2009 Author Share Posted May 22, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-839654 Share on other sites More sharing options...
savagenoob Posted May 22, 2009 Author Share Posted May 22, 2009 Also, I do not get this error when running locally... Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-839697 Share on other sites More sharing options...
MadTechie Posted May 22, 2009 Share Posted May 22, 2009 Humm, are sockets installed and working ? check phpinfo(); for sockets Sockets Support enabled Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-839782 Share on other sites More sharing options...
savagenoob Posted May 22, 2009 Author Share Posted May 22, 2009 I dont see the word sockets anywhere on phpinfo() so I guess not. :-\ Any suggestions? Would this cause this error? Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-840079 Share on other sites More sharing options...
MadTechie Posted May 22, 2009 Share Posted May 22, 2009 sockets not being installed.. your need to install them see here Note that under windows you just need to uncomment the line ;extension=php_sockets.dll so that it looks like extension=php_sockets.dll (without the ; at the start) in your php.ini Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-840156 Share on other sites More sharing options...
savagenoob Posted May 22, 2009 Author Share Posted May 22, 2009 Hey MadTechie, thanks for the help. I dont see the extension=php_sockets.dll option on the php5.ini file on the godaddy server OR locally. I added this to the end of php5.ini and am still getting same error. Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-840293 Share on other sites More sharing options...
MadTechie Posted May 22, 2009 Share Posted May 22, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-840311 Share on other sites More sharing options...
savagenoob Posted May 23, 2009 Author Share Posted May 23, 2009 Thanks again... I am going to just switch hosting services as Godaddy has too much stuff disabled for me. Does anyone have a hosting solution suggestion thats inexpensive yet has a complete PHP install? Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-840804 Share on other sites More sharing options...
MadTechie Posted May 24, 2009 Share Posted May 24, 2009 Heres a list from other members of course check it one some allow you to see a phpinfo(); page Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-841149 Share on other sites More sharing options...
savagenoob Posted May 28, 2009 Author Share Posted May 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-843910 Share on other sites More sharing options...
MadTechie Posted May 28, 2009 Share Posted May 28, 2009 You have 2 options when attaching files from a database via PHPMailer #1 write your own function to extent PHPMailer to encode and send the files data #2 use a temp file #2.1 pull data #2.2 create a file #2.3 send the file #2.4 unlink file Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-843966 Share on other sites More sharing options...
savagenoob Posted May 28, 2009 Author Share Posted May 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/159196-solved-php-mailer/#findComment-844576 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.