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.
Related
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.
I stumbled on the following script today for sending an e-mail using PHPMail.
<?php
$to = "some_address#domain.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "my_address#domain.com";
$headers = "From:" . $from;
mail($to, $subject, $message, $headers);
echo "Mail Sent.";
?>
Above can be runnable through php mail.php and instantly you'll get an e-mail sent to $to from $from despite not needing to set outgoing/ingoing servers out.
It really intrigued me, since my CMS uses an SMTP outgoing server (well, same way Mail PHP does), which I need to set up with my Outlook SMTP username and password - some sort of verification.
However, about Mail PHP just.. sends an e-mail. To the address you set it as. From the address you set it as.
Looking at PHP docs it does not really reveal how it works. Does Mail PHP not have any issues with spamming since anyone can send anyone anything anytime programmatically without verification of the from identity?
EDIT:
It's rather funny the people in the comments were talking about the POTUS, since I had the exact thing in mind:
It did land in my junk folder, but I'm sure it isn't hard to make this look convincing enough and still be considered "oh damn spam filter lost my e-mail!"
The mail function uses the settings from php.ini. The details of this configuration can be found in Mail Runtime Configuration.
The defaults can be set in php.ini, although you can override them using ini_set.
I bet you sent the mail from a PHP script on a hosted server. That server probably has SMTP settings configured beforehand. If you would try this locally on a WAMP/LAMP server, you would have to do this configuration yourself, since PHP cannot read your Outlook/WhateverMailclient settings.
As stated in the comments, you can specify the sender/from address yourself. SMTP doesn't require this to be the actual sender domain, so that's why this works. The missing link is the pre-configured SMTP server of your host.
Some relay servers do check for this, and your mail might be blocked or sent to a junk mail folder. You can however configure this in your DNS to indicate that <Your server's IP> is indeed allowed to send email for <yourdomain>. For more information about that subject, you might want to read this question on ServerFault.
It uses the smtp protocol or send_mail, you can even configure what php should use to send mails in php.ini. It can send e-mail but the e-mail will end-up in your spam filter take a look to DKIM and SPF records for more information
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'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);
}
<?php
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
When I run these script I get these error
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:\xampp\htdocs\website\mail.php on line 7
What I have to do now? Could anyone tell me the way to do it ? Okay I have found that file but what are the fields I need to update could you suggest me some code so that i paste it these and save?
You have to configure your php.ini with a valid smtp server and email address.
You need to configure PHP to use a working SMTP service in order to send SMTP email. Here's an article that discusses the subject.
Basically, it appears that the SMTP configuration for your PHP instance is using default values, which point to localhost. But your local computer doesn't seem to be running an SMTP service. So you'll need to point is to a server that is running one, and one which your application is permitted to use.
I guess that this question is the same as your other question...
If so, I guess you are trying to send an email through GMail's SMTP server. Their server requires authentication, which PHP's mail function doesn't support.
As I answered you in the other question, you can use Zend_Mail to do this. You can also use PEAR Mail like in the example in the other question.
Either way you will need to download some external file, include it in your code and use it.