Jump to content

Recommended Posts

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 by genxer
Link to comment
Share on other sites

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);
}

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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: jazzman
Your Reset Key: 5f4dcc3b5aa765d61d8327deb882cf99

You can reset your password by accessing the following link: reset.com/index.php?a=recover&r=1

Edited by jazzman1
Link to comment
Share on other sites

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 by genxer
Link to comment
Share on other sites

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);
Link to comment
Share on other sites

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);
Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.