Jump to content


Photo

Smtp Mail

smtp send email smtp email function

  • Please log in to reply
19 replies to this topic

#1 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 28 March 2013 - 08:04 PM

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, 28 March 2013 - 08:05 PM.


#2 trq

trq

    Advanced Member

  • Administrators
  • 31,032 posts
  • LocationSydney, Australia.

Posted 28 March 2013 - 08:18 PM

I'd start by removing the error suppressor from your call to mail and see if your getting any error.

http://thorpesystems.com | http://proemframework.org | http://github.com/trq

SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
OPM - My Linux package manager.


#3 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 28 March 2013 - 08:23 PM

Hello,

 

i dont see any error but don't send emails.



#4 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 29 March 2013 - 06:30 AM

The script is fine.

 

Which e-mail client you're using to send mails?



#5 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 March 2013 - 07:27 AM

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



#6 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 March 2013 - 07:55 AM

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

 

 



#7 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 29 March 2013 - 08:32 AM

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...ername-password



#8 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 March 2013 - 08:38 AM

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...ername-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.
 



#9 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 29 March 2013 - 10:13 AM

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.o...cs/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, 29 March 2013 - 10:16 AM.


#10 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 March 2013 - 11:07 AM

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.o...cs/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, 29 March 2013 - 11:08 AM.


#11 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 29 March 2013 - 11:19 AM

No problem.
 

Attached Files



#12 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 March 2013 - 11:26 AM

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


#13 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 29 March 2013 - 11:33 AM

Which editor you are using?

 

Attach the file with error.



#14 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 March 2013 - 11:43 AM

I attached my function.php when i upload it i did say viewing White blank page

Attached Files



#15 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 29 March 2013 - 11:49 AM

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 :)



#16 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 March 2013 - 12:20 PM

I guess it's my fault and not working :) But I won't take much of your time:)

 

Thanks



#17 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 29 March 2013 - 12:41 PM

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


#18 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 March 2013 - 12:49 PM

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



#19 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 29 March 2013 - 12:53 PM

Do you have error reporting turned on and showing all errors?

 

Paste this on the top of your file:

 

error_reporting(-1); 


#20 genxer

genxer

    Member

  • Members
  • PipPip
  • 11 posts

Posted 29 March 2013 - 01:30 PM

I saw a lot error. I will try it and write here result.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com