1

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?

Jerodev
  • 32,252
  • 11
  • 87
  • 108
Kimberly
  • 11
  • 2

2 Answers2

1

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, e.g. 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;
}
Josh Harrison
  • 5,927
  • 1
  • 30
  • 44
1

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

Community
  • 1
  • 1
Lodder
  • 19,758
  • 10
  • 59
  • 100
  • When I used your code in a php-file to test it out, I get a blank screen. i placed it in the rootdirectory of the website, maybe that's the problem? I don't even get the 'error sending email' echo. – Kimberly Oct 06 '14 at 14:37
  • @Kimberly - You can't simply use Joomla code in a separate PHP file. If you wish to do this, you you need to import the Joomla framework. See my updated answer – Lodder Oct 06 '14 at 14:40
  • if you are using a php file outside of the joomla framework, you need to load the joomla framework into that file. http://stackoverflow.com/questions/23937651/load-joomla-3-x-framework-and-modules-in-external-php-file – TEN Design Oct 06 '14 at 14:42
  • Hey Lodder, didn't know that, oops! Trying now! – Kimberly Oct 06 '14 at 14:44
  • It's getting a little over my head now, I uploaded the script as you told me to, with the joomla framework imported in the rootmap. From root, it's the same JPATH_BASE as in the example, right? – Kimberly Oct 06 '14 at 14:49
  • The current definition for `JPATH_BASE` is `../`, so this is the value that will possibly need to be changed. If you provided your file structure in your question, I would be able to give you a more accurate answer ;) – Lodder Oct 06 '14 at 14:51
  • Okay, I'm sorry :) I'm in /domains/mydomain.nl/htdocs/shop/ There's the testfile. Total Joomla root. Is that what you needed to know? – Kimberly Oct 06 '14 at 14:52
  • So the PHP file is in the root of your Joomla installation (same directory as *configuration.php*) ? – Lodder Oct 06 '14 at 14:53
  • This should work then: `define('JPATH_BASE', __DIR__);` – Lodder Oct 06 '14 at 14:58
  • I've created the file like you told, and it says 'Mail sent' but I'm not receiving. Is this helpfull to see where the problem is at? – Kimberly Oct 06 '14 at 15:30
  • If you're not receiving the mail then it will be a server related issue or a problem with your email client. Make sure you check the spam folder for your email account – Lodder Oct 06 '14 at 15:31
  • We interchanged the entire mail-code with Core PHP mail, and now it's working. What a work ;) – Kimberly Oct 07 '14 at 07:54