send emails with flutter web - php

i tried to use mailer package but its not supporting web , also i tried xampp send mail with gmail smtp but it gives me error
: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first.
any solution ?
<?php
$to_email = 'email#gmail.com';
$subject = "change pw";
$body = "pwppwpwpwp";
$headers = "From: email#gmail.com";
if (mail($to_email, $subject, $body, $headers))
{
echo "Email successfully sent to $to_email...";
}
?>

Your server wants encrypted transmission which mail() cannot offer (TLS stands for Transport Layer Security) In short, mail() sucks and it sucks for ages. Not sure why this garbage is still in the language. It is very plain, dumb and usually useless function supporting nothing modern mail servers require or support. You always want to use literally anything available but mail() i.e your framework's mailer class or PHPMailer instead.

Related

whats wrong with my php mail() function

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.

PHP mail() function sucess, but didn't receive any email

I'm try to sent email by my localhost php, but the problem is i didn't receive anything in my email, what should i configure?
Here is my code
$to="someone#gmail.com";
$name="jason";
$subject="test message";
$header="From: $name";
$message="blah blah blah";
$sentmail=mail($to,$subject,$message,$header);
echo $sentmail ? "email send" : "email send fail"?
as the result was "email send"
There are 2 reason not to send email from your localhost..
You don't have mail server setup in your local environment
You are not using SMTP service to send the email.
So either you have to configure the mail server but I don't think that this is a handy solution.
Better you try to use SMTP service. To do this it will be better if your use PHPMailer.
Here is an example using PHPMailer class.
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.example.com"; // SMTP server example
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "username"; // SMTP account username example
$mail->Password = "password";
You can use this class for any kind of email as a alternative of PHP : mail().
mail function will Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
mail function will not check whether mail reached in your inbox
http://php.net/manual/en/function.mail.php
You can't check whether mail has been delivered, but you can check whether the recipients opened your mail with tracking pixel https://support.google.com/dfp_premium/answer/1347585?hl=en
You should integrate a mail server in your local machine to send mail.The php mail function return true if all parameters are correct, it will not check delivery status.
Read this, http://www.zenddeveloper.com/how-to-send-emails-from-localhost-apachephp-server/
and http://roshanbh.com.np/2007/12/sending-e-mail-from-localhost-in-php-in-windows-environment.html
You need to have a mail server to send emails in localhost.Check PHP : send mail in localhost
By default, PHP's mail() function will deliver mail to the sendmail program on Linux.
For sendmail to work, you are required to have a properly configured and functioning MTA. For example, postfix is an MTA that is relatively easy to configure.
When configuring your MTA, you can either configure it to send mail directly, as a mail server on the internet, or to relay your mail to another server.
Configuring your own MTA to deliver mail directly is not for the light-hearted. Sending email has become complicated now, requiring a lot of work to be able to have your mail accepted by major mail servers like gmail or yahoo.
If your ISP provides an outgoing mail server and is happy to relay mail for you, you can set up postfix to relay all mail via that server instead, and save yourself some configuration hassle. If you use postfix, this simply requires setting it up like the example under Postfix on a null client in the postfix configuration.
The main thing to remember, no matter how you are configuring your mail server, is to avoid setting it up to relay incoming mail on the outgoing network (ie, setting it up as an open relay). In the null mailer example configuration, the line inet_interfaces = loopback-only achieves this.
Note that an alternative to setting up postfix or something as an MTA is to uses PHP's own built in SMTP support, which essentially means you are using PHP itself as an MTA which only forwards mail to a relay.
The advantage to using a dedicated MTA like postfix is reliability. Postfix can queue email if there is a temporary problem reaching the external mail relay. It also returns as soon as the mail has been queued, so your PHP mail function will execute much faster and won't need to wait while the mail is delivered to the external mail relay.
You need to have the content-type on your header. To make it easier, you could write simple function and then call it. Here's an example:
function sendMail($to, $title, $url, $from, $username, $password) {
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$title.' <'.$from.'>' . "\r\n";
$subject = 'Welcome to '.$title;
$message = 'Thank you for joining <strong>'.$title.'</strong><br /><br />Your username: <strong>'.$username.'</strong><br />Your Password: <strong>'.$password.'</strong><br /><br />You can log-in at: '.$title.'';
return #mail($to, $subject, $message, $headers);
}

SMTP server response: 550 Invalid recipient to a simple email feature

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))

Problem with Free SMTP Server in php code

I wrote php code for use to contact us form
but I can not find free SMTP server to use it.
I Try to use SMTP Server For Gmail but I found this error.
Warning: mail() [function.mail]:
"sendmail_from" not set in php.ini or
custom "From:" header missing in
C:\www\htdocs\contactUs.php on line
25"
line 25 is :
mail ($to,$subject,$body,$headers);
statement that indicate using Gmail SMTP Server is :
ini_set("SMTP","smtp.gmail.com");
SO,can U help me ?:(
You need a From: [VALID EMAIL] header of the message when you send the message. Try doing something like this:
$headers = array(
'From: me#example.com',
'Mime-Type: text/plain; charset=utf-8',
);
$dest = 'some_user#example.com';
$subj = 'test';
$message = 'hello world';
mail($dest, $subj, $message, implode("\r\n", $headers));
Also, the mail function is meant to be used as a frontend to the mail daemon that's running on the same server the web server is running on. Since most *NIX boxes have both, it usually works.
What I would not recommend, however, is using some remote server to send your mail. It's much more efficient and reliable (not to mention looking more professional) to just have the same server send the message as the one that generated the message.
Setting up your own SMTP server is easy and free and more flexible than Gmail. Gmail WILL NOT send messages whose From: header does not match either the main account address or a connected address.

Trouble getting simple php mail script to work on OSX

I am trying to get this simple php mail script to send mail to my email addres (mike_minerva#yahoo.com) and I cannot get it to work. I set my sendmail_path in php.ini to the right folder (/etc/sbin/sendmail) but that did not seem to help. What else could I be missing? The script always returns failure.
<?php
$to = "mike_minerva#yahoo.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
if(mail($to,$subject,$message,$headers))
echo "Mail Sent.";
else
echo "failure";
?>
SwiftMailer is a good library for the purpose of authenticating to your SMTP server to send mail.
http://swiftmailer.org/
try to use PEAR MAIL package.
In case anyone else comes to this question via google, another main cause of php mail not working is that the function is blocked on many servers due to the danger of outgoing spam.
There are some good smtp mail classes out there that are very easy to use. I only use mail() for debugging purposes... almost never in a live environment.

Categories