Do I understand correctly what I read on the CI website for the email class that if I am using PHP mail() that I don't need to do any configuring?
Here is my email in my controller. It is not sending. We are on a new server and I'm wondering what if anything I need to configure.
$this->email->from('oemsales#xxxx.com', 'OEM Sales');
$this->email->to('shummel#xxxx.com');
$this->email->subject('Contact Page Request');
$this->email->message($message);
$this->email->send();
$message is defined higher up in the code. This worked on our old server.
you can find following information in php.ini file. SMTP value contains the address of your mail server, you can change it to your mail server address.
[mail function]
SMTP = localhost
smtp_port = 25
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
I am trying to send an email using mail function in php. I have read the documentation and followed the examples but in vain. I don't know if I am doing anything wrong.
Can anyone please help me. I also followed other examples from the community without success.
And here also;
Send email with PHP from html form on submit with the same script
Here is my code:
$name =array($_POST['name'],$_POST['email'],$_POST['phone'],$_POST['comments']);
$to = "fasdjgasgd#yahoo.com";
$subject = "Form submission";
$message = "$name[0] wrote the following: <br/> $name[3]";
$header = "FROM:".$name[1];
mail($to, $subject, $message, $header);
Your server does not have local mailserver.
There are few solutions:
Install local mail server if you have sufficient rights
Change your PHP settings to use other mail server (other open mailserver or auth-based ones like Gmail, Yahoo etc)
Use one of available mail libraries which supports IMAP / POP3 to handle mail sending.
SwiftMailer or Pear Mail are one of most commonly used.
PHP must be configured correctly in the php.ini file with the details of how your system sends email. Open php.ini file available in /etc/ directory and find the section headed [mail function].
Windows users should ensure that two directives are supplied. The first is called SMTP that defines your email server address. The second is called sendmail_from which defines your own email address.
The configuration for Windows should look something like this:
[mail function]
SMTP = localhost
sendmail_from = email#domain.com
This link will help you.
I noticed a couple other posts around that were similar to my problem but found that they weren't specific to my scenario or I am just not understanding things very well.
My situation: I am trying to send mail from a LAMP server using the PHP mail() function. I want to relay the mail to another dedicated mail server.
Problem: It seems I am not able to send mail...sometimes. Sometimes it seems capable of sending mail to accounts outside of the domain but it fails to send any mail to accounts within the domain/network. I have seen logs often complaining about it not being able to authenticate to the domain controller...but it shouldn't have to worry about that should it?
I guess the part I am confused about is does the PHP mail() function automatically create an SMTP message to the server? Or do I have to set the php.ini settings to look at the localhost and then configure sendmail/postfix to send the message to the mail server. Also, why would it bother to authenticate with the domain controller if I only specified that the LAMP server try to connect with the mail server?
Hopefully someone can help me get this sorted out. It's been bothering me for a while now and haven't been able to find a solution.
Thank you,
does the PHP mail() function automatically create an SMTP message to
the server? Or do I have to set the php.ini settings to look at the
localhost and then configure sendmail/postfix to send the message to
the mail server
PHP's mail() function doesn't do that much by itself. On linux, it will typically connect to a local instance of sendmail or similar, using settings defined in php.ini. Check out this section from example php.ini:
[mail function]
; For Win32 only.
; SMTP = localhost
; smtp_port = 25
; For Win32 only.
;sendmail_from = me#example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail -t -i
For windows, SMTP server at configured port is used by mail(). For linux, defined sendmail path is used.
Using other words, PHP mail() function on windows connects to a SMTP server, be it local or remote. PHP mail() on Linux cannot do the same. On Linux, the function will only use a local sendmail installation that you need to set up yourself to connect to a SMTP server. Alternative for that kind of configuration is to use PHPMailer, Swiftmailer, Zend_Mail or similar, that provide SMTP functionality by themselves.
why would it bother to authenticate with the domain controller if I
only specified that the LAMP server try to connect with the mail
server?
I'm far from being an expert on this, but as far as I've understood, you need to be authenticated user in your network to access outside resources which mailing would need. A domain controller gives out that kind of permissions.
Start using Swiftmailer (documentation) or PhpMailer, your life will be easier...
Swiftmailer example:
require_once 'lib/swift_required.php';
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john#doe.com' => 'John Doe'))
->setTo(array('receiver#domain.org', 'other#domain.org' => 'A name'))
->setBody('Here is the message itself');
$mailer->send($message);
PhpMailer example :
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->AddAddress("whoto#otherdomain.com", "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I prefer Swiftmailer, but you select you best choice ;-)
When i send mail php from my server it works fine.But when i placed the code in my client server.it shows mail sending failed.what is the problem.
Your PHP server does not configured for mail. Basically mail function uses sendmail on UNIX systems. But for Windows it's remain unconfigured. You need to configure from PHP.ini file.
For example:
[mail function]
; For Win32 only.
SMTP = smtp.live.com
smtp_port = 25
username = my mail
password = my pass
I use the latest WAMP and I get this when I try to send emails:
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:\wamp\www\main\createaccount.php on line 8
Message delivery failed...
The message:
$to = "xxx#hotmail.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>");
}
Do you need do download a "mailserver" also?
Please help.
This works for me and should work for you: Use Fake Sendmail and a webhost mail server (i.e. - Godaddy, 1and1, etc.).
1.) Download the sendmail zip and extract it to C:\Wamp\bin\sendmail (for purposes of this example).
2.) Edit C:\wamp\bin\sendmail\sendmail.ini and set the following to your mail server's requirements (mine are below):
smtp_server=mail.yourdomain.com
smtp_port=26
smtp_ssl=none
;default_domain=yourdomain.com
auth_username=smtpuser#yourdomain.com
auth_password=smtppassword
;pop3_server=
;pop3_username=
;pop3_password=
;force_sender=
;force_recipient=
3.) Set the path of sendmail.exe in your php.ini file.
[mail function]
; For Win32 only.
SMTP =
; For Win32 only.
sendmail_from =
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\wamp\bin\sendmail\sendmail.exe -t"
4.) Restart Wampserver.
You might have success using Gmail, but there are a few extra tweaks to make it work. I prefer using the mail server of the webhost where I upload my code.
You are not running an smtp server on your machine, but you don't have to. Just set SMTP to a open smtp server for example:
ini_set('SMTP', 'smtp.yourisp.com');
Take a look at your ISP's home page or http://www.e-eeasy.com/SMTPServerList.aspx for list of SMTP servers.
If you have a desktop mail program, you can use the same address as you use for outgoing mail.
I think your mail server (SMTP) outgoing mail server is not configured in your php.ini file.
Have a look at this:
http://email.about.com/od/emailprogrammingtips/qt/Configure_PHP_to_Use_a_Remote_SMTP_Server_for_Sending_Mail.htm
Also hotmail doesn't allow you to use their mailservers. You should use yahoo or gmail.
Are you sure these servers have a mail program installed on them? If not, that's your problem. For example, XAMPP comes with a mail program called Mercury which you must start before you can send mail through the server.
Follow this article, it works if you have a gmail account.
or at least any email account in which you know the server, port and this stuff.
Send Email From localhost
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");