smtp mail in php

Reply

Join Date: Jan 2008
Posts: 8
Reputation: vipin_php is an unknown quantity at this point 
Solved Threads: 0
vipin_php vipin_php is offline Offline
Newbie Poster

Re: smtp mail in php

 
0
  #11
Jan 23rd, 2008
i just came to run the code


<?phpinfo()
?>





Here i came to notice a strange thing that in the Registered stream socket transports the ssl and tls is missing, kindly try the same in Ur system and intimate me bcuz i hope my ssl is not enabled,i have disabled my antivirus and firewall as U said, but now getting the error as

Warning: fsockopen() [function.fsockopen]: unable to connect to tls://smtp.gmail.com:465 (Unable to find the socket transport "tls" - did you forget to enable it when you configured PHP?) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\new.php on line 17

Warning: fgets(): supplied argument is not a valid stream resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\new.php on line 19




One more doubt is that, what should i replace in the below mentioned line, presently i have given
$localhost = $_SERVER['REMOTE_ADDR'];
MY CURRENT SCRIPT LINE
$localhost = $_SERVER['192.168.1.2 '];



I WOULD ALSO ATTACH THE OUTPUT GOT WHEN I RAN PHPINFO WITH THIS, kindly take a look
Attached Files
File Type: doc phpinfo.doc (132.0 KB, 11 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 11
Reputation: galeej is an unknown quantity at this point 
Solved Threads: 0
galeej galeej is offline Offline
Newbie Poster

Re: smtp mail in php

 
0
  #12
Jan 23rd, 2008
thanks digital-ether ...your solution worked 200% for me..
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,081
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: smtp mail in php

 
0
  #13
Jan 23rd, 2008
Originally Posted by galeej View Post
thanks digital-ether ...your solution worked 200% for me..
No problem

vipin_php, what OS and Server are you using? It looks like you don't have TLS support.

I just tested the gmail smtp and it also accepts non-encrypted SMTP transfer. So you could use a simple tcp://smtp.gmail.com for your host and 25 for the port if you don't mind sending non-secure emails.

Otherwise you have to set up TLS support on your PHP build.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 8
Reputation: vipin_php is an unknown quantity at this point 
Solved Threads: 0
vipin_php vipin_php is offline Offline
Newbie Poster

Re: smtp mail in php

 
0
  #14
Jan 23rd, 2008
Thank U very much for Ur reply.

I reinstalled the whole thing including apache server2.2.8 and php5.2.5 and downloaded open ssl0.9.8g and installed them , now it is working fine and showing

- 0connection accepted
220 mx.google.com ESMTP f10sm4556194rvb.17
Continuing


Now my problem is that i am expecting a mail to my mail id for eg:xxx@gmail.com but i am not getting it, i enabled the POP service also in my gmail, what may be the problem? kindly help, i am attaching the coding also with this mail in the form of a.php, please have a look at it.
Attached Files
File Type: php a.php (2.8 KB, 6 views)
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,081
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: smtp mail in php

 
0
  #15
Jan 23rd, 2008
Originally Posted by vipin_php View Post
Thank U very much for Ur reply.

I reinstalled the whole thing including apache server2.2.8 and php5.2.5 and downloaded open ssl0.9.8g and installed them , now it is working fine and showing

- 0connection accepted
220 mx.google.com ESMTP f10sm4556194rvb.17
Continuing


Now my problem is that i am expecting a mail to my mail id for eg:xxx@gmail.com but i am not getting it, i enabled the POP service also in my gmail, what may be the problem? kindly help, i am attaching the coding also with this mail in the form of a.php, please have a look at it.
Are you using your Gmail email as the sender? I think you'll have to use your gmail email, or another email that you have verified with Gmail as your email under the account that logs into SMTP.

Also, try dumping $logArray to see how far you got.

eg:

  1. echo '<pre>'.implode("\r\n", $logArray).'</pre>';
Plase that just before the return in the function.

One problem I see with the script is that it has no error handling at all. If the SMTP server closes the connection mid-way, the script keeps sending data, and listening for responses.

Since php streams as 'blocking' (listen until some data is received) by default, the script will hang until killed - since there is no more data coming.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 8
Reputation: vipin_php is an unknown quantity at this point 
Solved Threads: 0
vipin_php vipin_php is offline Offline
Newbie Poster

smtp mail in php

 
0
  #16
Jan 24th, 2008
i have included the line which U gave and now getting the output like this, kindly go through the code rewritten by me which i am attaching with this mail and correct the code if necessary and give me the guide lines also, the output is like:



Resource id #2
- 0
220 mx.google.com ESMTP b8sm865562rvf.31
connection accepted
220 mx.google.com ESMTP b8sm865562rvf.31
Continuing
Connected to: 220 mx.google.com ESMTP b8sm865562rvf.31
Connected to: 220 mx.google.com ESMTP b8sm865562rvf.31

250 mx.google.com at your service
Connected to: 220 mx.google.com ESMTP b8sm865562rvf.31

250 mx.google.com at your service

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31
Connected to: 220 mx.google.com ESMTP b8sm865562rvf.31

250 mx.google.com at your service

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31
Connected to: 220 mx.google.com ESMTP b8sm865562rvf.31

250 mx.google.com at your service

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31
Connected to: 220 mx.google.com ESMTP b8sm865562rvf.31

250 mx.google.com at your service

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31
Connected to: 220 mx.google.com ESMTP b8sm865562rvf.31

250 mx.google.com at your service

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31
Connected to: 220 mx.google.com ESMTP b8sm865562rvf.31

250 mx.google.com at your service

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31
Connected to: 220 mx.google.com ESMTP b8sm865562rvf.31

250 mx.google.com at your service

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31
Connected to: 220 mx.google.com ESMTP b8sm865562rvf.31

250 mx.google.com at your service

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

530 5.7.0 Must issue a STARTTLS command first b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

502 5.5.1 Unrecognized command b8sm865562rvf.31

502
Attached Files
File Type: php e.php (3.4 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 8
Reputation: vipin_php is an unknown quantity at this point 
Solved Threads: 0
vipin_php vipin_php is offline Offline
Newbie Poster

Re: smtp mail in php

 
0
  #17
Jan 24th, 2008
sorry the previous post was not correct since i included the lines every where, now i am giving the right one , kindly take a look at the php script which i am attaching with this post and make necessary corrections if necessary and guide me to clear this problem, thank U very much for Ur support. The output is pasted below- 0connection accepted


220 mx.google.com ESMTP g1sm960727rvb.0
Continuing


Connected to: 220 mx.google.com ESMTP g1sm960727rvb.0

Connected to: 220 mx.google.com ESMTP g1sm960727rvb.0

250 mx.google.com at your service

530 5.7.0 Must issue a STARTTLS command first g1sm960727rvb.0

502 5.5.1 Unrecognized command g1sm960727rvb.0

502 5.5.1 Unrecognized command g1sm960727rvb.0

530 5.7.0 Must issue a STARTTLS command first g1sm960727rvb.0

530 5.7.0 Must issue a STARTTLS command first g1sm960727rvb.0

502 5.5.1 Unrecognized command g1sm960727rvb.0

502 5.5.1 Unrecognized command g1sm960727rvb.0

502
Attached Files
File Type: php a.php (2.9 KB, 5 views)
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,081
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: smtp mail in php

 
0
  #18
Jan 24th, 2008
Originally Posted by vipin_php View Post
sorry the previous post was not correct since i included the lines every where, now i am giving the right one , kindly take a look at the php script which i am attaching with this post and make necessary corrections if necessary and guide me to clear this problem, thank U very much for Ur support. The output is pasted below- 0connection accepted


220 mx.google.com ESMTP g1sm960727rvb.0
Continuing


Connected to: 220 mx.google.com ESMTP g1sm960727rvb.0

Connected to: 220 mx.google.com ESMTP g1sm960727rvb.0

250 mx.google.com at your service

530 5.7.0 Must issue a STARTTLS command first g1sm960727rvb.0

502 5.5.1 Unrecognized command g1sm960727rvb.0

502 5.5.1 Unrecognized command g1sm960727rvb.0

530 5.7.0 Must issue a STARTTLS command first g1sm960727rvb.0

530 5.7.0 Must issue a STARTTLS command first g1sm960727rvb.0

502 5.5.1 Unrecognized command g1sm960727rvb.0

502 5.5.1 Unrecognized command g1sm960727rvb.0

502
Try writing the STARTTLS command to the SMTP server after HELO.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 8
Reputation: vipin_php is an unknown quantity at this point 
Solved Threads: 0
vipin_php vipin_php is offline Offline
Newbie Poster

Re: smtp mail in php

 
0
  #19
Jan 24th, 2008
can U please specify how to issue the STARTTLS command

when i wrote like this

fputs($smtpConnect, "STARTTLS $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['starttlsresponse2'] = "$smtpResponse";

i got a syntax error
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 8
Reputation: vipin_php is an unknown quantity at this point 
Solved Threads: 0
vipin_php vipin_php is offline Offline
Newbie Poster

smtp mail in php

 
0
  #20
Jan 24th, 2008
i have made the coding like this, now the STARTTLS error is gone but a syntax error is coming, pls help
<?php
function authgmail($from, $namefrom, $to, $nameto, $subject, $message)
{
$smtpServer = "smtp.gmail.com"; //does not accept STARTTLS
$port = "587"; // try 587 if this fails
$timeout = "45"; //typical timeout. try 45 for slow servers
$username = "xxx@gmail.com"; //your gmail account
$password = "abc"; //the pass for your gmail
$localhost = $_SERVER["REMOTE_ADDR"]; //requires a real ip
$newLine = "\r\n"; //var just for newlines
/* you shouldn't need to mod anything else */
//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
echo $errstr." - ".$errno;
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
echo $output;
return $output;
}
else
{
$logArray['connection'] = "Connected to: $smtpResponse";
echo "connection accepted<br>".$smtpResponse."<p />Continuing<p />";
echo $tadr;
}
//you have to say HELO again after TLS is started
fputs($smtpConnect, "EHLO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse1'] = "$smtpResponse";
//you have to say STARTTLS again after TLS is started
fputs($smtpConnect, "STARTTLS $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['starttlsresponse2'] = "$smtpResponse";
//you have to say HELO again after TLS is started
fputs($smtpConnect, "EHLO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse2'] = "$smtpResponse";
//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";
//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";
//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";
//email from
fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";
//email to
fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";
//construct headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto $to" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

//observe the . after the newline, it signals the end of message
fputs($smtpConnect, "To: <$to>\r\nFrom: $from\r\nSubjectsubject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data2response'] = "$smtpResponse";

// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
$a='Mail Sent Sucessfully';
echo '<pre>'.implode("\r\n", $logArray).'</pre>';
return($a);
}
authgmail("admin@smallbusiness.local","vvv","xxx@gmail.com","mmm","mail","message");
?>





now i am getting an output like this


- 0connection accepted
220 mx.google.com ESMTP b39sm1796682rvf.8
Continuing


Connected to: 220 mx.google.com ESMTP b39sm1796682rvf.8

250-mx.google.com at your service, [59.94.135.253]

250-SIZE 28311552

250-8BITMIME

250-STARTTLS

250 ENHANCEDSTATUSCODES

555 5.5.2 Syntax error b39sm1796682rvf.8

250-mx.google.com at your service, [59.94.135.253]

250-SIZE 28311552

250-8BITMIME

250-STARTTLS

250
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC