uzair
uzair

Reputation: 766

Php email not working error

I am using xampp 1.7.4 (PHP 5.3.5) and when i send emails to my email address its working. and even i used mail server as examples its not working. below is the code.

<?php
    ini_set("SMTP","mail.sweetinteractive.com");
    $suc = mail("[email protected]","Learning PHP","Message is not working ","From: [email protected]");
    if($suc){
        echo "Mail sent";
    } else {
        echo "Mail sending Failed.";
    }
?>

And even i tried out working with our mail server. But its showing and error

Warning: mail() [function.mail]: SMTP server response: 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1) in C:\xampp\htdocs\LearnPhp\email1.php on line 3

Upvotes: 0

Views: 4176

Answers (5)

Rafee
Rafee

Reputation: 4078

Please configure your php.ini and sendmail.ini files in xampp folder.

First : need to change the fields in php.ini (rootdrive:\xampp\php\php.ini)


(Note : semicolon ';' signifies a comments in ini files)

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.sweetinteractive.com
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [email protected]

second step : change the sendmail.ini file (rootdirectory:\xampp\sendmail\sendmail.ini)


note : remove semicolon (;) form give below fields and make changes in sendmail.ini file

smtp_server=mail.sweetinteractive.com

; smtp port (normally 25)

smtp_port=25

[email protected]
auth_password=give your password here without any quotes

I believe this should gonna work. Because you are not providing any authentication parameters in previous post.

Note : after making the changes in php.ini and sendmail.ini files, stop the apache service from Xampp control panel and run it again.

and your php code


<?php
    ini_set("SMTP","mail.sweetinteractive.com");
    $suc = mail("[email protected]","Learning PHP","Message sending will work now","From: [email protected]");
    if($suc){
        echo "Mail sent";
    } else {
        echo "Mail sending Failed.";
    }
?>

Upvotes: 0

DaveRandom
DaveRandom

Reputation: 88647

You have two options:

Change you system's host name to an FQDN (a bit extreme for this operation and may not even be possible in your setup, depending on many factors), or use PEAR::Mail or similar approach that allows you to specify the name used in the HELO/EHLO.

Upvotes: 0

tripleee
tripleee

Reputation: 189327

You seem to be missing the closing quote on the "From:" header.

Upvotes: 1

Plipus Tel
Plipus Tel

Reputation: 755

Make sure the SMTP in your php.ini is correct, and appropriate it to your mail server.

Upvotes: 0

ty812
ty812

Reputation: 3323

Your system has to send a so-called fully qualified domain name, see https://www.rfc-editor.org/rfc/rfc2821#section-4.1.1.1

This is most likely an anti-spam protection setting in your mailserver - it prevents "normal" client machines from sending in mail directly, a tactic that often is used by malware.

Upvotes: 0

Related Questions