Copy link to clipboard
Copied
I have a strange problem when running forgotten.php. The program works alright initially with the setting of mail_connector.php as below. I managed to send and received email. Everything works fine intially. After sometime, I found problem running the same program again. This time it generates error message of 'Notice: Underfined index: calvin_cccc@yahoo.com in c:\vhosts\phpcs5\lesson8\scripts\request_reset.php on line 25' and also message 'No connection could be made because the target machine actively refused it.'
Any idea why ?
Mail_Connector.php
<?php
$mailhost = 'mail.agri-organica.com';
$mailconfig = array('auth' => 'login',
'username' => 'calvin@agri-organica.com',
'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp($mailhost, $mailconfig);
Zend_Mail::setDefaultTransport($transport);
If it works once, it should work all the time unless there has been a change to the code or your mail authentication settings.
The error message says that the problem is on line 25 of request_reset.php, not Mail_Connector.php. The example code in the book on that line looks like this:
$mail->setFrom('webmaster@example.com', 'DW CS5 with PHP');
That sets the From header in the email. To prevent spammers from using the mail server as a spam relay, it's common to reject mail that doesn't come from an
...Copy link to clipboard
Copied
If it works once, it should work all the time unless there has been a change to the code or your mail authentication settings.
The error message says that the problem is on line 25 of request_reset.php, not Mail_Connector.php. The example code in the book on that line looks like this:
$mail->setFrom('webmaster@example.com', 'DW CS5 with PHP');
That sets the From header in the email. To prevent spammers from using the mail server as a spam relay, it's common to reject mail that doesn't come from an authorized source. You're logging into the agri-organica.com SMTP server, but using a yahoo.com email address in the From header. I suspect that the server is rejecting the mail because the From header doesn't use an agri-organica.com address. Change the address in line 25 of request_reset.php to an agri-organica.com address, and it will probably work.
Copy link to clipboard
Copied
I changed the From header using agri-organica.com address and send to yahoo address. This time it shows:
'No connection could be made because the target machine actively refused it.'
Request Received
An email has been sent to your registered address with instructions for resetting your password.
Request_reset.php
---------------------
<?php
$errors = FALSE;
$result = FALSE;
if ($_POST) {
require_once('library.php');
require_once('mail_connector.php');
try {
$val = new Zend_Validate_EmailAddress();
if (!$val->isValid($_POST['email'])) {
$errors = TRUE;
}
if (!$errors) {
$sql = $dbRead->quoteInto('SELECT user_id, first_name, family_name, email FROM users WHERE email = ?', $_POST['email']);
$result = $dbRead->fetchRow($sql);
if (!$result) {
$errors = TRUE;
} else {
// update database and send mail
$token = md5(uniqid(mt_rand(), TRUE));
$data = array('token' => $token);
$where = $dbWrite->quoteInto('email = ?', $_POST['email']);
$dbWrite->update('users', $data, "user_id = {$result['user_id']}");
}
$mail = new Zend_Mail('UTF-8');
$mail->addTo($result['email'], "{$result['first_name']} {$result['family_name']}");
$mail->setSubject('Instructions for resetting your password');
$mail->setFrom('calvin@agri-organica.com', 'Calvin');
$link = "http://phpcs5/lesson8/reset.php?id={$result['user_id']}&token=$token";
$message = "Use the following link to reset your password. This link can be used once only. $link";
$mail->setBodyText($message, 'UTF-8');
$mail->send();
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
Copy link to clipboard
Copied
Good new ! After I re-entered the setting in mail_connector.php and request_rest.php, everything is working fine now.
Thank You !
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more