Copy link to clipboard
Copied
Hello:
I am following the book "Adobe Dreamweaver CS5 with PHP" by David Powers (an excellent book I might add) and am currently going over chapter 8. (Zending email). I have completed the section concerning processing of a simple user feedback script, and I beleive I have my connector script, and code correct. My testing server is running and correctly defined in DW. When I attempt to submit the form in a browser window, I get the message "could not open socket" at the top of the browser document window. I assume this involves adjusting a configuration file but I can not figure out where it is. Any help out there?
My setup:
Windows 7
Apache2.2.17
PHP5.3.4
ZendFramework-1.11.4-minimal
Copy link to clipboard
Copied
EagerNewby wrote:
When I attempt to submit the form in a browser window, I get the message "could not open socket" at the top of the browser document window.
Glad you like the book. If the message is appearing at the top of the window, it means an exception has been thrown. Assuming you are working through the book in sequence, you were able to communicate successfully with the database in Lesson 7. That means the exception is probably being thrown by Zend_Mail (which would make sense, because I think it uses a socket connection for SMTP).
To verify where the exception is being thrown, change the try clause in library.php like this:
catch (Exception $e) {
echo 'Class: ' . get_class($e) . ' says: ' . $e->getMessage();
}
If it's one of the Zend_Mail classes, the problem lies with making contact to your mail server. If the username or password were wrong, you should get a message indicating a problem with authentication. Since it says it can't open the socket, it sounds more like you're using the wrong protocol or that there's something, such as a software firewall, preventing the connection. Try turning off your firewall temporarily to see if it makes any difference.
Copy link to clipboard
Copied
Boy, this one sure has me stumped.
Despite using the amendment to the catch block that you so graciously suggested, and turning off my firewall, and antivirus software, all I get is the error message "could not open socket" at the top of the browser (various) document window (and a resetting of all fields and textarea):
Here are my files. (I understand I will be changing my passwords, and getting a new recaptcha key, but I am desperate to fix this):
I also amended the mail_connector.php script using the (Outgoing Mail Server: (SSL) server306.webhostingpad.com (server requires authentication) port 465) choice below with the same result.
My hosting company provided this to me for manual setting of email:
Manual Settings
Mail Server Username: test1+housecalls4pets.com
Incoming Mail Server: mail.housecalls4pets.com
Incoming Mail Server: (SSL) server306.webhostingpad.com
Outgoing Mail Server: mail.housecalls4pets.com (server requires authentication) port 2626
Outgoing Mail Server: (SSL) server306.webhostingpad.com (server requires authentication) port 465
Supported Incoming Mail Protocols: POP3, POP3S (SSL/TLS), IMAP, IMAPS (SSL/TLS)
Supported Outgoing Mail Protocols: SMTP, SMTPS (SSL/TLS)
***************************************************************************************
library.php:
<?php
// Adjust the path to match the location of the library folder on your system
$library = 'C:/php_library/ZendFramework-1.11.4-minimal/library';
set_include_path(get_include_path() . PATH_SEPARATOR . $library);
require_once('Zend/Loader/Autoloader.php');
try {
Zend_Loader_Autoloader::getInstance();
$write = array('host' => 'localhost',
'username' => 'cs5write',
'password' => 'Bow!e#CS5',
'dbname' => 'phpcs5');
$read = array('host' => 'localhost',
'username' => 'cs5read',
'password' => '5T@rmaN',
'dbname' => 'phpcs5');
// Comment out the next two lines if using mysqli
// and remove the comments from the last two lines
$dbWrite = new Zend_Db_Adapter_Pdo_Mysql($write);
$dbRead = new Zend_Db_Adapter_Pdo_Mysql($read);
//$dbWrite = new Zend_Db_Adapter_Mysqli($write);
//$dbRead = new Zend_Db_Adapter_Mysqli($read);
}
catch (Exception $e) {
echo 'Class: ' . get_class($e) . ' says: ' . $e->getMessage();
}
***************************************************************************************
mail_connector.php:
<?php
$mailhost = 'smtp.mail.housecalls4pets.com';
$mailconfig = array('auth' => 'login',
'username' =>'test1@housecalls4pets.com',
'password' => 'Buffy1481',
'port' => '2626');
$transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
Zend_Mail::setDefaultTransport($transport);
***************************************************************************************
process_comments.php
<?php
require_once('library.php');
$errors = array();
try {
$public_key = '6LekzsUSAAAAAP99fQ32-j-qlp2wUWqeUc3_HvkX';
$private_key = '6LekzsUSAAAAAHxKj135LEE9zoAxQng1A3azJYgE';
$recaptcha = new Zend_Service_ReCaptcha($public_key, $private_key);
if (isset($_POST['send'])) {
// validate the user input
if (empty($_POST['recaptcha_response_field'])) {
$errors['recaptcha'] = 'reCAPTCHA field is required';
} else {
$result = $recaptcha->verify($_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
if (!$result->isValid()) {
$errors['recaptcha'] = 'Try again';
}
}
$val = new Zend_Validate_Alnum(TRUE);
if (!$val->isValid($_POST['name'])) {
$errors['name'] = 'Name is required';
}
$val = new Zend_Validate_EmailAddress();
if (!$val->isValid($_POST['email'])) {
$errors['email'] = 'Email address is required';
}
$val = new Zend_Validate_StringLength(10);
if (!$val->isValid($_POST['comments'])) {
$errors['comments'] = 'Required';
}
if (!$errors) {
// create and send the email
require_once('mail_connector.php');
$mail = new Zend_Mail('UTF-8');
$mail->addTo('test2@housecalls4pets.com', 'A N Other');
$mail->setFrom('test1@housecalls4pets.com', 'Zend Mail Test');
$mail->setSubject('Comments from feedback form');
$mail->setReplyTo($_POST['email'], $_POST['name']);
$text = "Name: {$_POST['name']}\r\n\r\n";
$text .= "Email: {$_POST['email']}\r\n\r\n";
$text .= "Comments: {$_POST['comments']}";
$html = "<p><strong>Name: </strong><a href='mailto:{$_POST['email']}'>{$_POST['name']}</a></p>";
$html .= '<p><strong>Comments: </strong>' . nl2br($_POST['comments']) . '</p>';
$mail->setBodyText($text, 'UTF-8');
$mail->setBodyHtml($html, 'UTF-8');
$success = $mail->send();
if (!$success) {
$errors = TRUE;
}
}
}
} catch (Exception $e) {
echo $e->getMessage();
}
?>
***************************************************************************************
comments.php:
<?php
require_once('scripts/process_comments.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Us</title>
<link href="../../styles/users_wider.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Get In Touch</h1>
<form id="form1" name="form1" method="post" action="">
<?php if (isset($success) && !$errors) { ?>
<p>Thank you. Your comments have been sent.</p>
<?php } elseif (isset($success) && $errors) { ?>
<p>Sorry, there was a problem. Please try later.</p>
<?php } ?>
<p>All fields are required</p>
<p>
<label for="name">Your name:</label>
<input value="<?php if ($_POST && $errors) {
echo htmlentities($_POST['name'], ENT_COMPAT, 'UTF-8');
}?>" type="text" name="name" id="name" />
<span>
<?php if ($_POST && isset($errors['name'])) {
echo $errors['name'];
} ?>
</span></p>
<p>
<label for="email">Email address:</label>
<input value="<?php if ($_POST && $errors) {
echo htmlentities($_POST['email'], ENT_COMPAT, 'UTF-8');
}?>" type="text" name="email" id="email" />
<span>
<?php if ($_POST && isset($errors['email'])) {
echo $errors['email'];
} ?>
</span></p>
<p>
<label for="comments">Comments:</label>
<textarea name="comments" id="comments" cols="45" rows="5"><?php if ($_POST && $errors) {echo htmlentities($_POST['comments'],ENT_COMPAT, 'UTF-8'); }?></textarea>
<span>
<?php if ($_POST && isset($errors['comments'])) {
echo $errors['comments'];
} ?>
</span></p>
<?php if (isset($errors['recaptcha'])) {
echo "<p><span>{$errors['recaptcha']}</span></p>";
}
echo $recaptcha->getHtml(); ?>
<p>
<input type="submit" name="send" id="send" value="Send Comments" />
</p>
</form>
</body>
</html>
***************************************************************************************
Copy link to clipboard
Copied
EagerNewby wrote:
My hosting company provided this to me for manual setting of email:
Manual Settings
Mail Server Username: test1+housecalls4pets.com
Incoming Mail Server: mail.housecalls4pets.com
Incoming Mail Server: (SSL) server306.webhostingpad.com
Outgoing Mail Server: mail.housecalls4pets.com (server requires authentication) port 2626
Outgoing Mail Server: (SSL) server306.webhostingpad.com (server requires authentication) port 465
Supported Incoming Mail Protocols: POP3, POP3S (SSL/TLS), IMAP, IMAPS (SSL/TLS)
Supported Outgoing Mail Protocols: SMTP, SMTPS (SSL/TLS)
If that's the case, your mail_connector script is wrong. This is what you have:
<?php
$mailhost = 'smtp.mail.housecalls4pets.com';
$mailconfig = array('auth' => 'login',
'username' =>'test1@housecalls4pets.com',
'password' => 'Buffy1481',
'port' => '2626');
$transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
Zend_Mail::setDefaultTransport($transport);
It should be this:
<?php
$mailhost = 'mail.housecalls4perts.com';
$mailconfig = array('auth' => 'login',
'username' => 'test1+housecalls4pets.com',
'password' => 'yourPassword',
'port' => 2626);
$transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
Zend_Mail::setDefaultTransport($transport);
Copy link to clipboard
Copied
Thanks for the suggestion. With the changes suggested (which I agree with and are my error, a humbling moment indeeed) I still got that dreaded message, "could not open socket" at the top of the browser window). I will call my hosting company tommarow. I hope you had a great 4th of July, although I don't imagine you celebrate it across the pond, like we do here in the US. Thanks again for your help!
Chip