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.
Related
I am trying to call the mail function, but whenever I put it in the script, the page does not load.
I have the following code for my php.ini file in XAMPP:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP=localhost
; http://php.net/smtp-port
smtp_port=80
auth_username = XX_MYEMAIL_XX
auth_password = XXXXX_MYPASSWORD_XX
I have a 64-bit computer, but an error message said it was missing a sendmail_from, so I gave this variable a value. I have Mercury running from XAMPP, but I don't know if I configured anything that needs to be configured.
I get the following error
mail(): Failed to connect to mailserver at "localhost" port 80, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
I used the following php code:
<?php
$header = "From: varunsingh87#yahoo.com";
$to_email = 'VSpoet49#gmail.com';
$subject = 'Testing PHP Mail';
$message = 'This mail is sent using the PHP mail function';
if (mail($to_email, $subject, $message)) {
echo "<p>Email sent!</p>";
} else {
echo "<p>Email not sent.</p>";
}
?>
Below this is the default html tags.
Update
I removed the sendmail_from and set the smtp_port to 25.
mail(): Bad Message Return Path i
Related
Warning: Bad Message Return Path (PHP)
Failed to connect to mailserver at "localhost" port 25
First, I never heard for mail server listening on port 80.
I have XAMPP installed too, but with configured with "smpt_port=25".
Second, you have "SMTP=localhost" so in order to send email you must have installed mail server on your machine, for example "Mercury" from XAMPP package.
Third, it can be very tricky to properly send email using "mail()" function (authentication, spam detection...) so best solution is to avoid usage of "mail()" function and use some robust library/component/script for that.
It is good advice by Baranix to learn how to use PhpMailer or SwiftMailer (my favourite) and configure them to target real, well configured mail server on real hosting.
Learn how to use PhpMailer and don't mess with this embarrassing mail function.
https://github.com/PHPMailer/PHPMailer/wiki/Tutorial
With this class you will send all messages with and without authorization, with or without tls/ssl and attachments (files, images).
!!! Install smtp server: hmailserver on localhost first !!!
https://www.hmailserver.com/download
And create your domain email mailbox.
Regards
http://php.net/manual/language.operators.errorcontrol.php
Let us learn about the # symbol, but be warned of a possible fake return status.
People typically try this first though
Try Catch Block
My forum has a problem with sending emails :
i have configured my mail settings as the following :
Mail Type : smtp
SMTP Host : myhost
Port : 587
Username & password : a valid email account on my domain
when i click on forget password to test sending emails i got the following message in error log:
Sender address is not valid for your login. Check your email program settings
I am pretty sure that this account is correct, and i tried to add test mail script to my host with the following code :
<?php
$mail = mail("myEmail", "wahahahahahaahahahahaa","I like spamming your inbox!!!", "From: Myself<your_email#here.com");
if(!$mail){
echo 'mail is not sent!';
} else {
echo 'mail is sent :-)';
}
?>
and it prints
mail is sent :-)
What i am missing here ?
I agree with Eggyal - it sounds like the hosted SMTP server is not allowing mail to be sent from the MAIL FROM address that you are using, with the authentication credentials that you are using.
To confirm this, and to rule-out a problem with the way that your application is trying to send the message - you might want to try sending a message through this SMTP server using a standard mail client (such as Thunderbird or Outlook), and using the same MAIL FROM address and authentication credentials that your application is using. If this fails with the same error, then you've confirmed that the hosted SMTP server is not allowing mail to be sent from the MAIL FROM address that you are using, with the authentication credentials that you are using.
Problem Solved.
I added my gmail on webmaster email, i changed it to domain email user then the problem is solved
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 am getting this error despite configuring php.ini to a valid send_from address. I know it is valid because it works when I send it from squirrel mail but when sending mail in php it will just not work. the invalid address presumably refers to the send_from address. so I can't see how it can think it's wrong. here is the php code:
$email="tobiasvogel1#googlemail.com";
$subject = "Your New Password";
$from="admin#dayshare.local";
$message = "Your new password is as follows:
xxxxxxxxxxxxxxxxxxxxxxxxxxx
This email was automatically generated.";
if(!mail($email, $subject,$message,$from)){
echo ("error");
}else echo "success";
and in php.ini:
SMTP = localhost
sendmail_from = admin#dayshare.local
550 Delivery is not allowed to this address
This error means that the sender is trying to send an email to an
address which he is not allowed to send to. This message is generated
after hMailServer has checked the IP range settings. As an example,
the default IP range configuration does not allow external users to
send messages to other external users. This is to prevent people from
using your server to send spam. So if an external user tries to send a
message to another external user, he will get this message.
That is the meaning of the error you are getting. This is from the hMailServer Documentation.
Can you try if the following will work?
<?php
mail('tobiasvogel1#googlemail.com','Test Email','This is a test email.',"From: tobiasvogel1#googlemail.com");
?>
If it doesn't work, then it's probably due to a misconfiguration in your hMailServer and you would need to check your hMailServer Logs.
The 4th parameter of the mail() function is not plain "from". In your code, you are only passing the email address without "From: " - The fourth parameter is for additional mail headers, so you have to format it like this:
mail($email, $subject,$message,"From: admin#dayshare.local\r\nX-Mailer: PHP");
I added another header as an example.
Try this, worked for me:
ini_set("sendmail_from", "info#yourdomain.com");
You need quotes and a semi-colon:
$email="tobiasvogel1#googlemail.com";
here is another solution - WAMP send Mail using SMTP localhost
KEEP IN MIND, everytime, after You change php.ini,
you must restart wamp (! ! !)
p.s. in php.ini, i have used:
SMTP = localhost
smtp_port = 25
sendmail_from = your_user#gmail.com
or if oyu cant edit php.ini, try to insert these lines in your php script.
ini_set("SMTP", "localhost");
ini_set("smtp_port", "25");
ini_set("sendmail_from", "your_user#gmail.com");
I have installed Apache and PHP on my Windows 7 PC. I learning the PHP now. Following is my PHP script to send email.
<?php
if(isset($_REQUEST['email']))
{
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
mail("padhy.surya#gmail.com","$subject","$message","From:","$email");
echo "Thank you for using the email !!!";
}
else
{
echo "Mail is not set properly. Please fill the form properly";
}
?>
I am using a html form to get the required parameters for sending email. Following is the error I am getting while I send the email.
Warning: mail() [function.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
C:\WebLearn\Apache-2.2\htdocs\SimpleWebsite\contact.php on line 7
Do I need to set anything to set in php.ini file or in httpd.conf? If yes how to configure it? Do I need an additional SMTP server on my PC to send email? Please suggest the necessary steps to send an email from my local PC.
The message is saying that it's trying to deliver the email to localhost:25, and there's nothing listening there.
PHP cannot email "the Internet" directly. The message must go to a mail server program such as Postfix or Sendmail or SSMTP, which then relays it to the appropriate destination.
You must install and configure a mail server program and set PHP to use it via php.ini. I believe you also have the option of configuring PHP to use a Sendmail binary instead of SMTP delivery.