genxer Posted March 29, 2013 Share Posted March 29, 2013 (edited) Hello, I don't know very good PHP, I have a problem with send email. My hosting working smtp support but i didn't add it. My function doing send recovery password.How can i add smtp support? function sendRecover($to, $title, $url, $from, $username, $salt) { $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: '.$title.' <'.$from.'>' . "\r\n"; $subject = 'Password Recovery - '.$title; $message = 'A password recover was requested, if you didn\'t make this action please ignore this email. <br /><br />Your Username: <strong>'.$username.'</strong><br />Your Reset Key: <strong>'.$salt.'</strong><br /><br />You can reset your password by accessing the following link: <a href="'.$url.'/index.php?a=recover&r=1" target="_blank">'.$url.'/index.php?a=recover&r=1</a>'; return @mail($to, $subject, $message, $headers); } Edited March 29, 2013 by genxer Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/ Share on other sites More sharing options...
trq Posted March 29, 2013 Share Posted March 29, 2013 I'd start by removing the error suppressor from your call to mail and see if your getting any error. Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421734 Share on other sites More sharing options...
genxer Posted March 29, 2013 Author Share Posted March 29, 2013 Hello, i dont see any error but don't send emails. Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421735 Share on other sites More sharing options...
jazzman1 Posted March 29, 2013 Share Posted March 29, 2013 The script is fine. Which e-mail client you're using to send mails? Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421768 Share on other sites More sharing options...
genxer Posted March 29, 2013 Author Share Posted March 29, 2013 The script is fine. Which e-mail client you're using to send mails? Yes it is fine but i need smtp support like PhpMailler but i didn'n integrate it in my function. My php knowledge basic. Regards Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421774 Share on other sites More sharing options...
genxer Posted March 29, 2013 Author Share Posted March 29, 2013 Im try with PhpMailler Still not working. function sendRecover($to, $title, $url, $from, $username, $salt) { require_once("class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->Host = "mail.site.com"; // SMTP servers $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "site@site.com"; // SMTP username $mail->Password = "mypass"; // SMTP password $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: '.$title.' <'.$from.'>' . "\r\n"; $subject = 'Password Recovery - '.$title; $message = 'A password recover was requested, if you didn\'t make this action please ignore this email. <br /><br />Your Username: <strong>'.$username.'</strong><br />Your Reset Key: <strong>'.$salt.'</strong><br /><br />You can reset your password by accessing the following link: <a href="'.$url.'/index.php?a=recover&r=1" target="_blank">'.$url.'/index.php?a=recover&r=1</a>'; $mail->From = "site@site.com"; $mail->Fromname = "Genxer"; $mail->AddAddress = $from; $mail->Subject = $subject; $mail->Body = $message; return @mail($to, $subject, $message, $headers); } Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421776 Share on other sites More sharing options...
jazzman1 Posted March 29, 2013 Share Posted March 29, 2013 I don't have any experience with phpMailer, but I'am sure that you're trying to set up that function in wrong way. If you want to set up the php mail function to use different mail servers using SMTP protocol you need to know few things. 1. What OS is running on the server 2. Under linux servers by default the php mail function uses a l sendmail inux client, so you need to create own sendmail configuration file(if you don't have any access to the server) setting its correct path into php.ini file. 3. On windows servers I don't know how to do this but I found this one on the web - http://stackoverflow.com/questions/112190/php-ini-smtp-how-do-you-pass-username-password Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421782 Share on other sites More sharing options...
genxer Posted March 29, 2013 Author Share Posted March 29, 2013 I don't have any experience with phpMailer, but I'am sure that you're trying to set up that function in wrong way. If you want to set up the php mail function to use different mail servers using SMTP protocol you need to know few things. 1. What OS is running on the server 2. Under linux servers by default the php mail function uses a l sendmail inux client, so you need to create own sendmail configuration file(if you don't have any access to the server) setting its correct path into php.ini file. 3. On windows servers I don't know how to do this but I found this one on the web - http://stackoverflow.com/questions/112190/php-ini-smtp-how-do-you-pass-username-password I hope so wrong way but i need try someting My hosting Linux server, and my hosting provider said we are stopped SMTP on our IIS all hosting server if you want send email you must add SMTP support on your code like PHPmailler they send me a sample php mail form (PHPmailler). How can i integrate it i dont know. Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421783 Share on other sites More sharing options...
jazzman1 Posted March 29, 2013 Share Posted March 29, 2013 (edited) Ok, I wrote a simple script using the same logic as your. Instead phpMailer I'm using another good php mail library - swiftMailer - http://swiftmailer.org/docs/sending.html This test I have made it from my local linux server but using my remote google mail account. Here is it: <?php require_once 'swiftmailer./lib/swift_required.php'; date_default_timezone_set('America/Toronto'); function sendRecover($to, $title, $url, $from, $username, $salt, $body) { $transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl') ->setUsername("yourName@gmail.com") ->setPassword("yourPassword"); ; // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); // Create a message $message = Swift_Message::newInstance($title) ->setContentType("text/html") ->setFrom(array($from)) ->setTo(array($to)) ->setBody($body) ; // Send the message $result = $mailer->send($message); return $result; } $url = 'reset.com'; $username = 'jazzman'; $salt = md5('password'); $body= <<<EOT A password recover was requested, if you didn't make this action please ignore this email. <br /> <br />Your Username: <strong>$username</strong><br />Your Reset Key: <strong>$salt</strong><br /> <br />You can reset your password by accessing the following link: <a href="$url/index.php?a=recover&r=1" target="_blank">$url/index.php?a=recover&r=1</a> EOT; sendRecover('jazzman@gmail.com', 'Wonderful Subject', 'smtp.example.com', 'jazzman@localdomain.com', 'jazzman', $salt, $body); Results: A password recover was requested, if you didn't make this action please ignore this email.Your Username: jazzmanYour Reset Key: 5f4dcc3b5aa765d61d8327deb882cf99You can reset your password by accessing the following link: reset.com/index.php?a=recover&r=1 Edited March 29, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421793 Share on other sites More sharing options...
genxer Posted March 29, 2013 Author Share Posted March 29, 2013 (edited) Ok, I wrote a simple script using the same logic as your. Instead phpMailer I'm using another good php mail library - swiftMailer - http://swiftmailer.org/docs/sending.html This test I have made it from my local linux server but using my remote google mail account. Here is it: <?php require_once 'swiftmailer./lib/swift_required.php'; date_default_timezone_set('America/Toronto'); function sendRecover($to, $title, $url, $from, $username, $salt, $body) { $transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl') ->setUsername("yourName@gmail.com") ->setPassword("yourPassword"); ; // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); // Create a message $message = Swift_Message::newInstance($title) ->setContentType("text/html") ->setFrom(array($from)) ->setTo(array($to)) ->setBody($body) ; // Send the message $result = $mailer->send($message); return $result; } $url = 'reset.com'; $username = 'jazzman'; $salt = md5('password'); $body= <<<EOT A password recover was requested, if you didn't make this action please ignore this email. <br /> <br />Your Username: <strong>$username</strong><br />Your Reset Key: <strong>$salt</strong><br /> <br />You can reset your password by accessing the following link: <a href="$url/index.php?a=recover&r=1" target="_blank">$url/index.php?a=recover&r=1</a> EOT; sendRecover('jazzman@gmail.com', 'Wonderful Subject', 'smtp.example.com', 'jazzman@localdomain.com', 'jazzman', $salt, $body); Results: I added this code in my function.php but it have a syntax problem? Cause i saw an error. i don't understand. Can you send me full code on .txt file? Many thanks for all answer and help. Edited March 29, 2013 by genxer Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421807 Share on other sites More sharing options...
jazzman1 Posted March 29, 2013 Share Posted March 29, 2013 No problem. swiftMailer.php Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421812 Share on other sites More sharing options...
genxer Posted March 29, 2013 Author Share Posted March 29, 2013 No problem. When i add this code my web site is not working. Just blank white page i think for following line cause when delete it my code is normal not syntax error. $body= <<<EOT A password recover was requested, if you didn't make this action please ignore this email. <br /> <br />Your Username: <strong>$username</strong><br />Your Reset Key: <strong>$salt</strong><br /> <br />You can reset your password by accessing the following link: <a href="$url/index.php?a=recover&r=1" target="_blank">$url/index.php?a=recover&r=1</a> EOT; sendRecover('jazzman@gmail.com', 'Wonderful Subject', 'smtp.example.com', 'jazzman@localdomain.com', 'jazzman', $salt, $body); Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421813 Share on other sites More sharing options...
jazzman1 Posted March 29, 2013 Share Posted March 29, 2013 Which editor you are using? Attach the file with error. Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421816 Share on other sites More sharing options...
genxer Posted March 29, 2013 Author Share Posted March 29, 2013 I attached my function.php when i upload it i did say viewing White blank page functions.php Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421818 Share on other sites More sharing options...
jazzman1 Posted March 29, 2013 Share Posted March 29, 2013 There is no problem with that script for me. Listen, don't copy/paste my heredoc (<<<EOT EOT;)just create own one with the same content or don't use heredoc, it's up to you Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421821 Share on other sites More sharing options...
genxer Posted March 29, 2013 Author Share Posted March 29, 2013 I guess it's my fault and not working But I won't take much of your time:) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421827 Share on other sites More sharing options...
jazzman1 Posted March 29, 2013 Share Posted March 29, 2013 Try to put a backslash before the first comma in the string, $body=<<<EOT A password recover was requested, if you didn\'t make this action please ignore this email. <br /> <br />Your Username: <strong>$username</strong><br />Your Reset Key: <strong>$salt</strong><br /> <br />You can reset your password by accessing the following link: <a href="$url/index.php?a=recover&r=1" target="_blank">$url/index.php?a=recover&r=1</a> EOT; sendRecover('jazzman@gmail.com', 'Wonderful Subject', 'smtp.example.com', 'jazzman@localdomain.com', 'jazzman', $salt, $body); Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421830 Share on other sites More sharing options...
genxer Posted March 29, 2013 Author Share Posted March 29, 2013 Try to put a backslash before the first comma in the string, $body=<<<EOT A password recover was requested, if you didn\'t make this action please ignore this email. <br /> <br />Your Username: <strong>$username</strong><br />Your Reset Key: <strong>$salt</strong><br /> <br />You can reset your password by accessing the following link: <a href="$url/index.php?a=recover&r=1" target="_blank">$url/index.php?a=recover&r=1</a> EOT; sendRecover('jazzman@gmail.com', 'Wonderful Subject', 'smtp.example.com', 'jazzman@localdomain.com', 'jazzman', $salt, $body); I deleted this line just for test. But still blank white page... I think have different poblem Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421831 Share on other sites More sharing options...
jazzman1 Posted March 29, 2013 Share Posted March 29, 2013 Do you have error reporting turned on and showing all errors? Paste this on the top of your file: error_reporting(-1); Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421833 Share on other sites More sharing options...
genxer Posted March 29, 2013 Author Share Posted March 29, 2013 I saw a lot error. I will try it and write here result. Quote Link to comment https://forums.phpfreaks.com/topic/276278-smtp-mail/#findComment-1421836 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.