would anyone be able to help me with my question..I am not able to send mail using mail() in php..Here is my code:
if (isset($_POST["from"])) {
$from = $_POST["from"]; // sender
$subject = $_POST["subject"];
$message = $_POST["message"];
$message = wordwrap($message, 70);
mail("test#example.com",$subject,$message,"From: $from\n");
echo "Thank you for sending us feedback";
}
while i am running this program in localhost,output showing as "Thank you for sending us feedback" , but not getting any mail in test#example.com.
Check your php.ini cofiguration file and add the mail server config:
SMTP = server ; mail server
smtp_port = 25 ; port
sendmail_from = your#email.com ;
Or
Use PHPMailer https://github.com/PHPMailer/PHPMailer to send via gmail, yahoo or any external mail server.
Related
$to = 'abc#xyz.com';
$subject = 'Feedback';
$finalmessage = "";
$from = 'def#ghi.com';
$finalmessage = $name . $address . $phnum . $email . $feedback;
$finalmessage = wordwrap($finalmessage, 70);
$mail=mail($to,$subject,$finalmessage,"From: $from\n");
if($mail){
echo "Thank you for using our mail form";
}else{
echo "Mail sending failed.";
}
Thats the code. At the end it displays "Thank you for using our mail form", but i am not receiving any mail. Any ideas whats going wrong?
if(isset($_POST['Submit'])){
$to="email";
// this is your Email address
$from = $_POST['Email_Address']; // this is the sender's Email address
$first_name = $_POST['Full_Name'];
$tel_num=$_POST['Telephone_Number'];
$msg=$_POST['Your_Message'];
$subject = "Full Name : ".$first_name;
$headers = "From: ".$first_name." <".$from.">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$message="Full Name : ".$first_name."<br><br>Telephone Number : ".$tel_num."<br><br>Message : ".$msg;
$bericht = nl2br($message);
mail($to,$subject,$message,$headers);
}
You need to configure SMTP settings of your local server in php.ini file as follows:
[mail function]
; For Win32 only.
SMTP = localhost // your smtp server
smtp_port = 25
Or you should give try to Swift Mailer or PHP Mailer
Try using fake sendmail to send emails in a windows enviroment.
http://jesin.tk/using-sendmail-on-windows/
Use php mailer() function
You can use PHPmailer :
http://phpmailer.codeworxtech.com/
Now
use following code -
<?php
require("class.phpmailer.php"); // give proper path of folder if needed
$mail = new PHPMailer();
session_start();
ob_start();
php?>
<your mail body goes here>
<?php
$body=ob_get_contents();
ob_end_clean ();
$to = 'abc#xyz.com';
$subject = 'Feedback';
$finalmessage = "";
$from = 'def#ghi.com';
$finalmessage = $name . $address . $phnum . $email . $feedback;
$finalmessage = wordwrap($finalmessage, 70);
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->IsHTML(true);
$mail=mail($to,$subject,$finalmessage,"From: $from\n");
if($mail){
echo "Thank you for using our mail form";
}else{
echo "Mail sending failed.";
}
You need to configure your mail SMTP in php.ini
It's quite simple, what is your ISP? For example, in comcast, just search in Google "comcast smtp address and port"
Take note of the SMTP address and Port, then go to your php.ini
Search for this configuration:
[mail function]
; For Win32 only.
SMTP = localhost // your smtp server
smtp_port = 25
Change the address with the SMTP and smtp_port. Then you should be able to send emails in your localhost
i am trying to send the contact form data to email using smtp server . but its not working and i dont know how to configure smtp, i googled it but didn't found any good solution. my php code for email sending is :
// Please specify your Mail Server - Example: mail.example.com.
ini_set("SMTP","ssl://smtp.gmail.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","465");
// Please specify the return address to use
ini_set("sendmail_from","chadhar313#gmail.com>");
$to ="chadhar313#yahoo.com";
$yourname = trim($_POST['yourname']);
$email = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$header = "Contact Form";
$message = "Name: $yourname \r\n Email: $email \r\n Subject:
$subject \r\n Message: $message";
$headers = "From:" . $yourname;
$mailsent = mail($to, $header, $message, $headers);
if($mailsent) {
$sent = true;
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 the /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] ; For Win32 only. SMTP = smtp.secureserver.net
; For win32 only sendmail_from = webmaster#tutorialspoint.com
I have a question for all you out there.
I've noticed that my php mail isn't sent anymore. So I looked into it to determine what the problem is but I can't seem to find it.
This is the case:
In powershell 3 (server 2012)I use the following command:
send-MailMessage -SmtpServer smtp.versatel.nl
and after giving the to e-mail address, a subject and a from address it sends the mail without any problem.
The code in the PHP file is:
INI_SET("SMTP", "smtp.versatel.nl");
$success = mail($to, $subject, $body, $header);
preg_match("/\d+/", $error["message"], $error);
if(!$success){$this->sFoutmelding ='Email is niet verstuurd.'.print_r($error);}
In the php.ini I disabled the default ini settings:
mail function]
; For Win32 only.
; SMTP = Smtp.versatel.nl
; smtp_port = 25
But still I get an error that the mail isn't sent:
Array ( )
Email is niet verstuurd.1
Why doesn't php send the mail when powershell does this perfectly?
Any ideas are welcome, I have searched on and off the whole week over the internet, but i can't find an answer.
*edit
I tried the var_dump and it gives, as expected, only a 'FALSE'.
Also the change in 'localhost' didn't do the trick. Still searching...
Its working, but still no explonation why :-) So if someone knows why, I like to know it too :-)
It still uses the same smtp server as without the phpmailer class. So the only thing I can think off is the fact that PHPmailer creates a different, more widly excepted, mail header than the default one of PHP.
I added the following code and class PHP mailer:
$success = $this->mail_attachment($to, $subject, $body);
protected function mail_attachment($mailto, $subject, $message) {
require_once("../PHPMailer/class.phpmailer.php");
//$file = $path.$filename;
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.versatel.nl"; // SMTP server
$mail->From = "noreply#provider.foo";
$mail->FromName = "Sendername";
$mail->AddAddress($mailto);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->WordWrap = 75;
//$mail->AddAttachment($file);
if(!$mail->Send()) {
echo 'Bevestigings e-mail is niet verzonden.';
echo 'Mailer error is: ' . $mail->ErrorInfo;
}
}
I have been trying to send mail using wamp server in my laptop. The SMTP server is presented in online.
Here is my php code to send mail:
<?php
ini_set( 'SMTP', "mail.vickey1192.co.in" );
ini_set( 'smtp_port', 26 );
ini_set( 'sendmail_from', "admin#vickey1192.co.in" );
$to = "balavickey1192#gmail.com";
$subject = "Acknowledgement";
$message = "Thank you for registering with us<br>";
$from = "no-reply#vickey1192.co.in";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
I also set my php.ini file like this:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.vickey1192.co.in
; http://php.net/smtp-port
smtp_port = 26
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = admin#vickey1192.co.in
This is the error I am getting:
Warning: mail() [function.mail]: SMTP server response: 550-Please turn on SMTP
Authentication in your mail client, or login to the 550-IMAP/POP3
server before sending your message. (vignesh-PC)
550-[115.118.170.201]:23328 is not permitted to relay through this
server 550 without authentication. in C:\wamp\www\mailtofunc.php on
line 12
What do I do now? Please help me guys...
I think its a problem with authentication. You need to add the SMTP user's username and password to the mail function to send the email.
//Using built in mail method
$mail = new PHPMailer();
$mail->Host = 'smtp.example.com'
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = 'your_username#example.com'; // a valid email here
$mail->Password = 'replace_with_your_password';
$mail->From = 'from#example.com';
$mail->AddReplyTo('from#example.com', 'Test');
$mail->FromName = 'Test SMTP';
$mail->AddAddress('test1#example.com', 'test2#example.com');
$mail->Subject = 'Test SMTP';
$mail->Body = 'Hello World';
$mail->Send();
You might be better off trying the PHP's Pear mail function, if you know how to use it.
//Using PEAR's mail function
<?php
include('Mail.php');
/* mail setup recipients, subject etc */
$recipients = "your_recipients#example.com";
$headers["From"] = "user#example.com";
$headers["To"] = "feedback#example.com";
$headers["Subject"] = "Some Subject";
$mailmsg = "Hello, This is a test.";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "smtp.example.com";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "smtpusername";
$smtpinfo["password"] = "smtpPassword";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);
?>
Your mail server requires authentication (username + password) before it will accept email from you. It is suggesting you either provide it via your SMTP connection (using SMTP AUTH, hopefully with TLS), or that you do a technique called POP before SMTP where you first login and 'check' your mail which will cause a temporary whitelisting of your host so it can send mail for a brief while afterward.
I am trying to send mail using php.And i am using WampServer.
so i tried the following code
ini_set("SMTP","smtp.gmail.com" );
ini_set("smtp_port","465");
ini_set('sendmail_from', 'person1#gmail.com');
$to = "person2#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "person1#gmail.com";
$headers = "From:" . $from;
$retval = mail($to,$subject,$message,$headers);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
but it take more time to connect and says could not connect with localhost.
Please help me in solving the problem
try this configuration:
http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/
this might help.
somehow, instead of "smtp.gmail.com", for me it works with "ssl:smtp.gmail.com"
This line:
ini_set("SMTP","smtp.gmail.com" );
should be
ini_set("SMTP","ssl:smtp.gmail.com" );
Also, see this response to a similar question: Send email using the GMail SMTP server from a PHP page
You're trying to send mail from your localhost (Your PC) I guess It's not setup to send mail. Move the script to a production server and it will work