• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Emails - PHP and Dreamweaver

New Here ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

I have made good progress with David Powers 'Training from the Source' until Chapter 8 - Emails.

I have the following message from the Mail Connector

Fatal error: Class 'Zend_Mail_Transport_Sendmail' not found inC:\Xampp\xampp\htdocs\phpcs5\lesson08\workfiles\scripts\mail_connector.php on line 7

The details I entered were as as follows:

<?php

$mailhost = 'smtp.btconnect.com';

$mailconfig = array('auth' => 'login',

'username' => 'mrwhitegrassroot@btconnect.com',

'password' => '************',

'ssl' => 'ssl');

$transport = new Zend_Mail_Transport_Sendmail('-fmrwhitegrassroot@btconnect.com');

Zend_Mail::setDefaultTransport($transport);

I have blotted out my password but I don't think that is the problem.

I currently have one active website on my remote server but that is a static site.

I tried to test the remote server without success probably because it is not linked up to PHP.

Could it be that the emails will not work until I have a remote server that is favourable to PHP?

TOPICS
Server side applications

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

Does your server have the ability to send email? Does it allow for secure sending?

This is what I do:

$todayis = date("l, F j, Y, g:i a") ;

$subject = Contact_From_Website;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n

Message: $notes \n

From: $visitor ($visitormail)\n

Telephone: $visitorphone ($visitorphone)\n

Additional Info : IP = $ip \n

";

$from = "From: $visitormail\r\n";

mail("youremail@company.com", $subject, $message, $from);

?>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

Can you add this to your code:

'ssl' => 'ssl',

'port' => '465');

Notice I've removed closing bracket next to ssl and replaced with comma. Added Port line and included closing bracket.

Also where are you calling your mail_connector.php script from? YOu should have it somewhere in your code where you say require_once or include_once... Can you post that as well for us please?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 04, 2013 Apr 04, 2013

Copy link to clipboard

Copied

Hi Sudarshan,

The error message was removed from the mail connector with the addition of the Port.

I received the following error message on the Feedback Form

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() inC:\Xampp\xampp\php\PEAR\Zend\Mail\Transport\Sendmail.php on line 98
Unable to send mail

I think this is because I was not on the remote server  - where I have a static website.

In response to your request re: require_once see below:

<?php
require_once('C:/Xampp/xampp/htdocs/phpcs5/lesson08/workfiles/scripts/library.php');
$errors = array();
try {
$public_key = '6Lfx_94SAAAAAJw0zHCQ8cpFhiCqs62O-2gGrEUI';
$private_key = '6Lfx_94SAAAAAJvjKoeCiNh1cCM3dJ2Xq1ibX5a9 ';
  $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(
'grassrootspublications@btconnect.com');
      $mail->setFrom(
'mrwhitegrassroot@btconnect.com');
      $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 = '<html><head><title>';
      $html .= $mail->getSubject();
      $html .='</title></head><body>';
      $html .= "<p><strong>Name: </strong><a href='mailto::{$_POST['email']}'>{$_POST['name']}</a></p>";
      $html .= '<p><strong>Comments: </strong>' . nl2br($_POST['comments']) . '</p>';
      $html .= '</body><html>';
      $mail->setBodyText($text, 'UTF-8');
      $mail->setBodyHtml($html, 'UTF-8');
      $success = $mail->send();
      if (!$success) {
       $errors = TRUE;
      }
}
}
  }catch (Exception $e) {
  echo $e->getMessage();
}
?>

I will be able to work on this more over the weekend.

Graham

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 05, 2013 Apr 05, 2013

Copy link to clipboard

Copied

Since you're testing locally, you probably dont have a mailserver on your local computer - which is why you're seeing that error.

Try it on your remote webserver. Or, from your local computer, change 'localhost' to a proper mailserver's IP or CNAME (mail.yourdomain.com) or something similar and test it out.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2013 Apr 07, 2013

Copy link to clipboard

Copied

Hello Sudarshan,

I have tried your suggestions apart from the CName.

The remote server where I have a static site came up with the Internet 404 error. When I changed the details locally I received the same error message as before

When I tried to find my mailserver IP all I got was my computer's IP. Then when I checked the properties of some of my normal email messages I noted that 127.0.01 is listed.

I also checked my mail servers:

Incoming Mail (POP3): pop.outlook.com

Outgoing Mail (SMTP): smtp.outlook.com

Port numbers: Incoming: 995

                     Outgoing: 587

I changed the Local Host details in the Library

Hope this information helps as I am sure I am missing something very small but important

Thanks

Graham

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Apr 07, 2013 Apr 07, 2013

Copy link to clipboard

Copied

lofty, it looks like you are trying to use either a testing server (that is not configured to be a mail server) or your local computer to test emails.

Assuming your hosting provider has a fairly standard system with complete php support, you should be using that remote server to test emails. That's what I do all the time. Any page I am working on is in a special subdirectory (or folder) called /testing/ or something else.

Navigate with your browser to that page and then try it there. THAT is the server that will need to run your server-side code, not your local computer or your testing server (if it is different from your remote host). It may have a different version of php on it, it may have a php configuration file that is different. There are so many variables that it just makes sense to do it on that remote server.

So, to prevent the wrong people from seeing your pages before they are ready to launch, set things up in a folder that is not accessible.

Then run your email tests, your sendmail tests and so on. This is what I do for my clients. It's what works.

Find out from your hosting provider what your port numbers should be in your php. Frankly, I don't call port numbers in mine, I just tell the server to send the mail; my code is posted above and it's simple.

I think you'll have better luck.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2013 Apr 07, 2013

Copy link to clipboard

Copied

mhollis55 wrote:

lofty, it looks like you are trying to use either a testing server (that is not configured to be a mail server) or your local computer to test emails.

He's using my book, which uses the Zend Framework to make an SMTP connection directly to a remote mail server. If set up correctly, it should work just fine. It does not require a local mail server.

Using the standard PHP mail() function does require a local mail server. The Zend Framework does not.

As I pointed out earlier, the original error message says that the required class can't be found. Sort that problem, and the issue should be fixed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 14, 2013 May 14, 2013

Copy link to clipboard

Copied

LATEST

Hi David

I have finally cracked and it worked.

I switched to another test site that I am developing as its code worked with Chapter 7.

Added a require_once to Mail Connector to link it with my Library file.

Once I did that  I had the 'could not find socket warning' Managed to find someone else you advised on that. It helped because there were inaccuracies in the settings.

Advice to anyone: Check your email settings with host provider before starting chapter 8.

Thanks for your help and to everyone else who contributed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2013 Apr 07, 2013

Copy link to clipboard

Copied

Moved to the Develop server-side applications in Dreamweaver forum.

Loftynorman wrote:

I have the following message from the Mail Connector

Fatal error: Class 'Zend_Mail_Transport_Sendmail' not found inC:\Xampp\xampp\htdocs\phpcs5\lesson08\workfiles\scripts\mail_connector .php on line 7

The error message tells you that the script cannot find the Zend_Mail_Transport_Sendmail class. This means that the Zend Framework is probably not in your PHP include path. See page 222 for details of how to set up the include path.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines