I can't send e-mail to outside of my domain using basic php mail function.It shows error when i want to send e-mail to yahoo or gmail or outside of my domain.The error is:Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay in C:\-----\email.php on line 6.My code is below.
$to = "testabc#gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
My e-mail server is Microsoft exchange server 2007.
Is their any well stablished php class or code available to send email.
pls help
That's a server configuration issue, it doesn't have anything to do with how you send emails. Apparently relaying is not allowed, and thus you are unable to send mails to external email addresses. So either change the "to" address to one that is allowed, use another SMTP server to send the mails or change the configuration of the current one.
Did you try using a email library like swift? http://swiftmailer.org/
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I want to send emails using php mail() function using xampp on ubuntu. But its not sent. Please check my code. Do I need to set any email server like gmail for it or I can do it without gmail?
<?php
$address = "kthakkar#argusoft.com";
$subject = 'Test email';
$body = 'If you can read this, your email is working.';
echo "Attempting to email $address...<br />";
if (mail($address, $subject, $body)) {
echo 'SUCCESS! PHP successfully delivered email to your MTA. If you don\'t see the email in your inbox in a few minutes, there is a problem with your MTA.';
} else {
echo 'ERROR! PHP could not deliver email to your MTA. Check that your PHP settings are correct for your MTA and your MTA will deliver email.';
}
?>
If I use smtp gmail account, its sending mails but not using php mail() as I dont want to share my gmail credentials.
try this:
How to configure XAMPP to send mail from localhost?
You can use other mail services, not only gmail. Later, when you have your own server, install your mail server :)
Am not having good knowledge in PHP, I have just started to work on it...
Now am trying to use mail() function as example given in w3schools.com
<?php
$to = "ramkumarpece05#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "ramp211087#gmail.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
for this am getting error message as follows
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify
your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in F:\contact.ph
p on line 7
Mail Sent.
where the php.ini file is located or i have to download it from the internet.....
Please help me to solve this issue...
You probably didn't install a mail server on your machine, you can install one for testing purposes (mail from your server will probably be marked as spam) or you can configure PHP to use your email account.
Your mail method is fine, your local server isn't. It is attempting to send the email but there is no SMTP server setup on your local server to send the email. You can install programs like Tomcat or Mercury which can handle the sending of the emails. You will just have to provide it some credentials to authenticate. I used my Gmail account's SMTP for example to send emails from my local server.
I would like to send an email from my PHP application. For this, I set up my website in IIS on my Windows server 2008. Can I install the Windows SMTP server.
Then I create a test page to send an email:
<?php
Ini_set ('SMTP', 'localhost');
Ini_set ('sendmail_from', 'myEmailTest#local.com');
$to = 'myEmailTest#ExternalDomain.com';
$subject = 'Example subject';
$body = 'body ... With an example';
if(mail($to, $subject, $body)){
echo "Successful";
}else{
echo "Error";
}
?>
I also configure php.ini and SMTP E-mail in IIS like this:
[Mail function]
smtp = localhost
smtp_port = 25
Then I test sending my mail. When I send the email to an email address of the local domain to another email address in the local domain. Me back my page "Successful" and the email goes in the folder :
C:\inetpub\mailroot\Drop
By cons, if I send an email from an email address in the local domain email address to an external domain (# hotmail.com). Me my page returns "Error" and nothing happens.
I look at the log files of my SMTP server, but there is no error message.
Can you help me?
I successfully advanced a step. Now, when I send an email from an e-mail address of local domain to a e-mail address of an external domain (#hotmail.com), the mail is send to my PHP page, it gets stuck in against in the queue C:\inetpub\mailroot\Queue.
Does anyone know what is the problem?
Thank you
If your page is returning with an error (most likely a 500) then you need to have a look at the PHP error logs which are separate from the SMTP error logs. Please let us know what you find, as any error encountered while attempting to execute the php mail function, will show up in those logs.
My script to send an email via PHP is not working and I don't know why as there is no specific error. Please advise:
test#test.com is replaced with my real email address.
udrew_email("test#test.com", $_REQUEST["txtEmail"], "Gears Message", $_REQUEST["txtName"], $_REQUEST["txtMessage"]);
<?php
function udrew_email($strTo, $strFromEmail, $strSubject, $strFromName, $strBody)
{
$strHeaders = "From: " . $strFromName . "<" . $strFromEmail . ">" . "\r\n";
if (mail($strTo, $strSubject, $strBody, $strHeaders)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed.</p>");
}
}
?>
I get "Message delivery failed."
I've also tried placing constants in all the variables instead of requesting from my form.
Any help would be appreciated. Thanks.
mail() returns false if it was unable to handle the email over to an smtp server. On unix, that'd be the local sendmail/postfix/exim. On Windows, it's whatever smtp server is configured in php.ini SMTP and smtp_port options.
That can be because the smtp server isn't running or is mis-configured. It can also be because the email is so badly formed the server rejects it outright without even TRYING to deliver it onwards.
Check and make sure that your mail server is running, and that you have one installed and set up. If it is then check the log files for your mail server.
i am creating a website using php that sends confirmation messages through emails..
to edit my php.ini, i followed this walkthrough:
http://php.net/manual/en/ref.mail.php
i downloaded a free smtp server to test the connections, i used port 25, and the DNS server as localhost. I use this server to test if the email i send is being connected
i used this simple code to test the mail() function:
<?php
$to = 'myownemail#yahoo.com';
$subject = 'the subject';
$from = 'email#domain.com';
$message = 'hello';
if(mail($to, $subject, $message, "From: $from"))
echo "Mail sent";
else
echo "Mail send failure - message not sent"; ?>
when running, the smtp server indicates that the current active connection is the "myownemail#yahoo.com".
but the website shows this error message:
SMTP server response: 550 Invalid recipient
what should i do? i am very new to development and used smtp for the first time so i have no idea what is happening
PS. I got the smtp server here> softstack.com/freesmtp.html
For testing you could try this tool, called Test Mail Server Tool, instead. It has the benefit of not sending actual emails thus spamming your account, but saving/opening the email on your desktop, the same email which would have been sent. You can examine the headers this way and debug more easily and much faster. Note that it's useless in production, and testing remotely. It was not meant for that.
Remove $from in request header from inside quotes and try using a valid email address.
if(mail($to, $subject, $message, "From: " . $from))