PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a simple script to send HTML email. For some reason, it sends well one time and delays (if it sends at all) for hours another time. I've Googled the topic, and see that I'm not alone but have not found a concrete solution. Don't know if it makes a difference, but I'm using Linux hosting on Go Daddy.
I'm going through the exact same problem. I have about 7 php contact forms like this and I get some emails but most I do not.
This morning I sent a test mail through a php contact form and it worked. A client just now used the same exact one and I am not getting them. I tried the other php contact forms and none of them did.
There are some other headers that might be needed so the emails don't look like spam. Also there is an option for sendmail that tells what to add for the envelope sender. The apache user may need some privilege to do this though, not sure:
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Thanks Weirdan. I happened across Swift Mailer only a half an hour before I received your reply. Do you know much about configuring it? I was reading this:
Where do I get this information? Should I be able to send a basic HTML email using the code in the link that I listed above? I only ask that because the documentation on Swift Mailer's site show's a much lengthier script.
From someone who controls the mail server(s) for a domain which you want your messages to originate from. For example, to send messages from @gmail.com you need to find out their smtp server address on google's help pages (google 'swiftmailer gmail' - there should be ready-made examples). To send mail from your own domain - contact your hosting provider and ask for smtp server address and if you need to provide any login/password to it.
Should I be able to send a basic HTML email using the code in the link that I listed above?
<?php
require_once 'lib/swift_required.php';
$smtp = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465)
->setUsername('myuser@gmail.com')
->setPassword('password'); // omitted here for security
$mailer = Swift_Mailer::newInstance($smtp);
$message = Swift_Message::newInstance('Hello World');
$message
->setTo(array(
///'user1@example.org',
'me@sbcglobal.net' => 'sleepydad',
//'user3@exmaple.org' => 'Another User Name'
))
->setFrom(array('myfriend@yahoo.com' => 'Sam'))
//->attach(Swift_Attachment::fromPath('/path/to/doc1.pdf'))
//->attach(Swift_Attachment::fromPath('/path/to/doc2.pdf'))
->setBody(
//'Here is an image <img src="' . $message->embed(Swift_Image::fromPath('/path/to/image.jpg')) . '" />',
'Here is an image',
'text/html'
)
//->addPart('This is the alternative part', 'text/plain')
;
if ($mailer->send($message))
{
echo "Message sent!";
}
else
{
echo "Message could not be sent.";
}
?>
And I get the following:
Warning: fsockopen() [function.fsockopen]: unable to connect to smtp.gmail.com:465 (Connection timed out) in /home/content/s/l/e/sleepydad/html/kasebergkronies/lib/classes/Swift/Transport/StreamBuffer.php on line 233
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Connection timed out #110]' in /home/content/s/l/e/sleepydad/html/kasebergkronies/lib/classes/Swift/Transport/StreamBuffer.php:235 Stack trace: #0 /home/content/s/l/e/sleepydad/html/kasebergkronies/lib/classes/Swift/Transport/StreamBuffer.php(70): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home/content/s/l/e/sleepydad/html/kasebergkronies/lib/classes/Swift/Transport/AbstractSmtpTransport.php(101): Swift_Transport_StreamBuffer->initialize(Array) #2 /home/content/s/l/e/sleepydad/html/kasebergkronies/lib/classes/Swift/Mailer.php(74): Swift_Transport_AbstractSmtpTransport->start() #3 /home/content/s/l/e/sleepydad/html/kasebergkronies/swiftmail.php(30): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in /home/content/s/l/e/sleepydad/html/kasebergkronies/lib/classes/Swift/Transport/StreamBuffer.php on line 235
I tried socket 25 as was written in the example that I downloaded, but that didn't work. I Googled the issue and someone suggested socket 465. That's not working either. I think I'm close here. Can I bother you one more time?
sleepydad wrote:I tried socket 25 as was written in the example that I downloaded, but that didn't work. I Googled the issue and someone suggested socket 465. That's not working either. I think I'm close here. Can I bother you one more time?
I believe you need to specify the connection is encrypted, like this:
Sorry, still no go. This is beyond frustrating! I've posted the question in a couple other forums and will post a solution here for future reference if I get one. I REALLY do appreciate your time and efforts!
sleepydad wrote:Sorry, still no go. This is beyond frustrating! I've posted the question in a couple other forums and will post a solution here for future reference if I get one. I REALLY do appreciate your time and efforts!
When something doesn't work, especially after someone proposed a solution, please post the result and/or error messages.
Sorry, getting same error message as noted earlier:
"Warning: fsockopen() [function.fsockopen]: unable to connect to smtp.gmail.com:465 (Connection timed out) in /home/content/s/l/e/sleepydad/html/kasebergkronies/lib/classes/Swift/Transport/StreamBuffer.php on line 233 ..."
ON my contact forms I'm not even using headers, should I be using headers and could that be the reason why I only receive the first few submissions and then not receiving the rest?
Loougle wrote:ON my contact forms I'm not even using headers, should I be using headers and could that be the reason why I only receive the first few submissions and then not receiving the rest?