ryy705 Posted June 25, 2008 Share Posted June 25, 2008 Hello, How can I send smtp mail? Am I allowed to do it the following way? The current code generates the following error: 'Failed to connect to smtp.gmail.com:587 [sMTP: Failed to connect socket: Connection refused (code: -1, response: )]' What am I doing wrong? Thanks in advance. <?php include("Mail.php"); /* mail setup recipients, subject etc */ $recipients = "[email protected]"; $headers["From"] = "[email protected]"; $headers["To"] = "[email protected]"; $headers["Subject"] = "Test"; $mailmsg = "Hello, This is a test."; $smtpinfo["host"] = "smtp.gmail.com"; $smtpinfo["port"] = "587"; $smtpinfo["auth"] = true; $smtpinfo["username"] = "me"; $smtpinfo["password"] = "****"; /* Create the mail object using the Mail::factory method */ $mail_object =& Mail::factory("smtp", $smtpinfo); /* Ok send mail */ $mail = $mail_object->send($recipients, $headers, $mailmsg); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> Link to comment https://forums.phpfreaks.com/topic/111914-how-to-send-smtp-mail/ Share on other sites More sharing options...
grlayouts Posted June 25, 2008 Share Posted June 25, 2008 problem is not your code i would suggest email provider? Link to comment https://forums.phpfreaks.com/topic/111914-how-to-send-smtp-mail/#findComment-574465 Share on other sites More sharing options...
ryy705 Posted June 26, 2008 Author Share Posted June 26, 2008 I don't understand. Whats wrong with my email provider? Link to comment https://forums.phpfreaks.com/topic/111914-how-to-send-smtp-mail/#findComment-574706 Share on other sites More sharing options...
schme16 Posted June 26, 2008 Share Posted June 26, 2008 What grlayouts means is that Gmail (assumed from code) is disallowing you to connect on the smtp port specified... check with Gmail again to see if your using the right username format (some like just "username" some want "[email protected]" ) and re-check to make certain that your attempting all this on the right port (587 may or may not be correct, I'm not sure). If you still get errors, hit us back and we'll try again! Link to comment https://forums.phpfreaks.com/topic/111914-how-to-send-smtp-mail/#findComment-574736 Share on other sites More sharing options...
ryy705 Posted June 26, 2008 Author Share Posted June 26, 2008 I have a mail server(ssmtp) installed on my computer and it uses the same server name and port. Thats why I am using them. Shouldn't they work? Link to comment https://forums.phpfreaks.com/topic/111914-how-to-send-smtp-mail/#findComment-574762 Share on other sites More sharing options...
schme16 Posted June 26, 2008 Share Posted June 26, 2008 Any firewalls installed that could be blocking access? Also, so your details would look like this: include("Mail.php"); /* mail setup recipients, subject etc */ $recipients = "[email protected]"; $headers["From"] = "[email protected]"; $headers["To"] = "[email protected]"; $headers["Subject"] = "Test"; $mailmsg = "Hello, This is a test."; $smtpinfo["host"] = "localhost; $smtpinfo["port"] = "587"; $smtpinfo["auth"] = true; $smtpinfo["username"] = "me"; $smtpinfo["password"] = "****"; /* Create the mail object using the Mail::factory method */ $mail_object =& Mail::factory("smtp", $smtpinfo); /* Ok send mail */ $mail = $mail_object->send($recipients, $headers, $mailmsg); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } if the mail server is on your PC then it should be localhost as the host, else you have an essetially useless piece of software as your bypassing it. Link to comment https://forums.phpfreaks.com/topic/111914-how-to-send-smtp-mail/#findComment-574904 Share on other sites More sharing options...
ryy705 Posted June 26, 2008 Author Share Posted June 26, 2008 I am putting up code on an actual server. And its not working. When I run the mail function on my computer it sends out smtp mails using my gmail account. Because ssmtp is configured that way on my computer. However that isn't the case when I run the code on the real server. I need a way to connect to a particular email account from an actual server. I hope I was able to clearify. Link to comment https://forums.phpfreaks.com/topic/111914-how-to-send-smtp-mail/#findComment-575221 Share on other sites More sharing options...
ryy705 Posted June 27, 2008 Author Share Posted June 27, 2008 hmm.. I am trying the following code and its returning false. If there is no error in my code am I making a logical error? $server = "smtp.gmail.com"; fsockopen('tcp://' . $server, 587); Link to comment https://forums.phpfreaks.com/topic/111914-how-to-send-smtp-mail/#findComment-575619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.