简体   繁体   中英

E-mail not getting sent in Joomla in combo with VM

I'm new to SO, so bear with me please. I'm fairly noobish regarding code, I'm mostly a webdesigner, not developer. But my own webdeveloper is having a hard time with this problem so I'm trying to find some help where ever I can get. So, we got this problem on a Virtuemart shop, running version 2.5.23 of Joomla with VM 2.6.10.

Server info:

  • PHP Built On Linux web04 3.13.0-35-generic #62~precise1-Ubuntu
  • Database Version: 5.1.73-0ubuntu0.10.04.1-log
  • Database Collation: utf8_general_ci
  • PHP Version: 5.3.10-1ubuntu3.14
  • Web Server: Apache
  • WebServer to PHP Interface: apache2handler
  • Joomla! Version: Joomla! 2.5.23 Stable [ Ember ] 24-July-2014 14:00 GMT

So this is not sending mail anywhere. We got it on a testserver and over there, life is good. It's sending e-mail. The testserver is running PHP 5.24.

I've used this to see if this checks out:

<?php

$to = "dontsentmemail@gmail.com";
if( mail( $to , 'This is a test message.' , 'Is this working?' ) ) {
    echo 'Email sent.';
} else {
    echo 'Email failed to send.';
}

?>

This is working fine. And I'm about to pull out all my hair. We've tried SMTP mail handling, and again, working like a charm on the testserver but it won't work on the live site.

does anybody know if is VM/joomla is using mail() directly or maybe using JUtility::sendMail() as default, and if we can change that, to make it work? Anyone got any ideas?

EDIT

I wasn't aware Joomla already includes its own version of PHPMailer. See Lodder's answer for a better out-of-the-box solution!


Try switching to a specialist mail library, eg PHPMailer to send the mail, instead of php's mail function.

I too had a similar problem, emails sent but not delivered, and no bounce messages. PHPMailer managed to send email that also got delivered.

<?php
require_once('path/to/PHPMailerAutoload.php');

//Create a new PHPMailer instance
$mail = new PHPMailer();

// Set PHPMailer to use the sendmail transport
$mail->isSendmail();

// Set who the message is to be sent from
// Name is optional
$mail->setFrom('somebody@yourdomain.com', 'Joe Bloggs');

//Set who the message is to be sent to
// Name is optional
$mail->addAddress('dontsentmemail@gmail.com', 'Jane Bliggs');

//Set the subject line
$mail->Subject = 'Is this working?';

// Set plain text body
$mail->IsHTML(false);
$mail->Body = 'This is a test message.';

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
}

I would personally use Joomla's built-in JMail class which uses PHPMailer . Have a look at the following:

$mailer = JFactory::getMailer();

$mailer->setSender('dontsentmemail@gmail.com');
$mailer->addRecipient('from@emailaddress.com');
$mailer->setSubject('Your subject');

$body = "Some email text";
$mailer->setBody($body);

$send = $mailer->Send();
if ( $send !== true ) 
{
    echo 'Error sending email';
} 
else 
{
    echo 'Mail sent';
}

You may want to change from@emailaddress.com to whatever suits your needs. There are also some additional features for this class which can be found on the Joomla documentation:

http://docs.joomla.org/Sending_email_from_extensions

Update:

I wasn't aware that you were using a separate PHP file. At the top of your PHP file, you will need to import the Joomla framework like so:

define( '_JEXEC', 1 );
define('JPATH_BASE', __DIR__);
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );

$app = JFactory::getApplication('site');

You may need to change the value for JPATH_BASE so that your script points to the root of your Joomla site, relative to where you PHP file is located.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM