Andre malupet
Andre malupet

Reputation: 111

smtp, phpinfo, sendmail

I am trying to send email using PHPmailer but when I change the SMTP server in php.ini, it is not updating in the phpinfo - it's still showing localhost. I'm assuming that this why I'm getting the error SMTP Error: Could not connect to SMTP host.

Can you help me find the error and possible reasons why I can't change the SMTP server, even though I can change the smtp_port

I've already tried doing this with mail servers and I also had a lot of trouble installing pear so I just want to make this work. I've tried smtp.mail.yahoo.com, smtp.gmail.com, and our own mailserver, and it's still showing as localhost. I've also restarted each time I made the change

It's my 3rd day diagnosing the problem for sending a simple email (which I found much easier in asp.net). If you need any further information, please just let me know. Thank you in advance.

Upvotes: 1

Views: 3218

Answers (2)

STUART RICHES
STUART RICHES

Reputation: 21

Thinking further on this, I am using phpmailer, but didn't bother setting smtp server in php.ini. Instead I create a new class that extends phpmailer, and specify my SMTP settings in there, rather like below.

This allows me to configure SMTP settings for multiple sites without ever needing to touch php.ini or the standard phpmailer files.

<?php
require_once('initialise.inc.php');  // Initialising constants including LIB_PATH & DS
require_once(LIB_PATH.DS."phpmailer".DS."class.phpmailer.php");
require_once(LIB_PATH.DS."phpmailer".DS."class.smtp.php");

class my_phpmailer extends phpmailer {

    public $From = "[email protected]"; // Email Address
    public $FromName = "My Name"; // Name
    public $Host = "mailserver.example.com";
    public $Mailer = "smtp";
    public $WordWrap = 75;
    public $Username = "***************"; // SMTP account username
    public $Password = "********"; // SMTP account password


    function __construct() {
    }

    public function __toString() {
    return $this;
    }

Upvotes: 0

STUART RICHES
STUART RICHES

Reputation: 21

May be a stupid question, but are you using the correct php.ini file? - in many installations there may be more than one around. I always double check that the php.ini file I am changing is the one refered to in phpinfo()

Upvotes: 1

Related Questions