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
Related
Hi I am trying to test my PHP mail function but it is not working. I have shared hosting all of my website mail function are not working
<?PHP
$sender = 'xx#gmail.com';
$recipient = 'xx#gmail.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
I have also checked my php.ini if mail function is disabled but it is not disabled
disable_functions =
I also tried using Easy WP SMTP Plugin. But it is not working. I am sure that my settings are correct.
But this is what i got
SMTP ERROR: Failed to connect to server: Connection timed out (110)SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Thank you
i will send mail using php mail function but it can display some error..
Warning: mail(): Failed to connect to mail server at
"localhost" port 25, verify your "SMTP" and
"smtp_port" setting in php.ini or use ini_set() in
mail.php
<?PHP
$sender = 'sender123#gmail.com';
$recipient = 'resever123#gmail.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
If you are testing on your localhost you most likely dont have an SMTP setup. You have to setup an smtp connection for php to send the message.
I would suggest using something like phpmailer which makes it easier when working on local testing servers.
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.
I use jQuery validate form plugin to receive email from my form contact. My code seems to run but I don't get mail. I see the message "Form sent" in WAMP. I have configured my SMTP server and I don't have error message from WAMP.
My form : http://jsfiddle.net/Xroad/2pLS2/24/
What's wrong ?
<?php
if(isset($_POST) && isset($_POST['form_firstname']) && isset($_POST['form_name']) && isset($_POST['form_email']) && isset($_POST['form_telephone']) && isset($_POST['form_message'])) {
extract($_POST);
if(!empty($form_firstname) && !empty($form_name) && !empty($form_email) && !empty($form_telephone) && !empty($form_message)) {
$to = "XXXXXX#gmail.com"; // My real email
$subjet = "Contact from the site";
$msg = stripslashes($form_message);
$msg = "A question came \n
Firstname : $form_firstname \n
Name : $form_name \n
Email : $form_email \n
Message : $form_message";
mail($to, $subjet, $msg);
echo "Form sent";
} else {
echo "You have not filled in the field";
}
}
?>
<form id="form-general" action="php/traitement.php" method="post">
Well, in case a simple mail() function with no other code is not delivering mail to your inbox it seems like your SMTP has more to be configured.
Make mail("XXXXXX#gmail.com", "Contact from the site", "test") work first and the rest of your code is probably good to go.
UPDATE
SMTP default value is localhost. According to me you're not able to resolve the domain SMTP (the one that is currently in your php.ini)! You could check that in console with telnet SMTP 25 (you might need to enable telnet first).
Anyway make sure you have a MTA on the other side - my best guess would be you need to call your system administrator and ask him about your SMTP host and port.
Just to keep you alert - in case you need to authenticate against your MTA you'll have to find another solution, because php's mail() (according to my knowledge) can't do that. Search for SwiftMailer and PhpMailer, both coming with a lot of examples.
Update 2
Well, sendmail.exe comes with its own configuration file, where you need to enter your smtp server, port and credentials!
Update 3
sendmail.exe TLS support hasn't been updated since 2008. The windows version has its last update 3 years ago and depending on which download you've chosen you might end up with even older version. While it works in general, there have been a number of reports for problems.
Even the author sendmail.exe is recommending MSMTP as a great open source alternative, and even blat as a more powerful tool. The only drawback I see is that those have a little more options and use different configuration format, which might look like harder to be configured.
i think you have problem with your host, so we try to use gmail SMTP server to send emails.
in order to do so, i'm going to use an email library called Swift, download it free here http://swiftmailer.org/ once you downloaded it just rename the folder into swift and setup the $smtp_settings username and password (the one you use to login into your gmail account) and be sure that the required file
require_once dirname(__FILE__).'/swift/lib/swift_required.php';
is in the right path. (as it is now you can simply have the swift folder in the same root of the mail file)
<?php
function send_mail($to, $from, $subject='', $body='', $smtp=array()){
// be sure this point where the swift package is...
require_once dirname(__FILE__).'/swift/lib/swift_required.php';
$settings = (object)$smtp;
$transport = Swift_SmtpTransport::newInstance($settings->host, $settings->port, $settings->encryption)
->setUsername($settings->username)
->setPassword($settings->password);
$mailer = Swift_Mailer::newInstance($transport);
$_from = is_array($from) ? $from : array($from);
$_to = is_array($to) ? $to : array($to);
$message = Swift_Message::newInstance($subject)
->setFrom($_from)
->setTo($_to)
->setBody($body);
$result = $mailer->send($message);
return $result;
}
if(isset($_POST) && isset($_POST['form_firstname']) && isset($_POST['form_name']) && isset($_POST['form_email']) && isset($_POST['form_telephone']) && isset($_POST['form_message'])) {
extract($_POST);
if(!empty($form_firstname) && !empty($form_name) && !empty($form_email) && !empty($form_telephone) && !empty($form_message)) {
// SMTP Server Configuration
$smtp_settings = array(
'host' => 'smtp.gmail.com',
'port' => 465,
'encryption' => 'ssl',
'username' => 'XXXXXXXXXXX#gmail.com',
'password' => '************',
);
// Send an email to client and a copy to us...
$to = 'XXXXXXXXXXX#gmail.com'; // who receive
$from = array('XXXXXXXXXXX#gmail.com' => 'My Site Name'); // who send
$subject = 'Contact from the site';
//$message = stripslashes($form_message)."\r\n";
$message = 'A question came'."\r\n";
$message .= 'Firstname : '.$form_firstname."\r\n";
$message .= 'Name : '.$form_name."\r\n";
$message .= 'Email : '.$form_email."\r\n";
$message .= 'Message : '.$form_message."\r\n";
if(send_mail($to, $from, $subject, $message, $smtp_settings)){
echo "Email sent";
} else {
echo "Email not sent";
}
} else {
echo "You have not filled in the field";
}
}
?>
Based on the Joomla! documentation # http://docs.joomla.org/Sending_email_from_extensions, I'm trying to send emails with the code below:
function sendmail($file,$mailto)
{
$mailer =& JFactory::getMailer();
//var_dump($mailer); exit;
$config =&JFactory::getConfig();
$sender = array(
$config->getValue( 'config.mailfrom' ),
$config->getValue( 'config.fromname' )
);
$mailer->setSender($sender);
$recipient = array($mailto);
$mailer->addRecipient($recipient);
$body = "Your body string\nin double quotes if you want to parse the \nnewlines etc";
$mailer->setSubject('Your subject string');
$mailer->setBody($body);
// Optional file attached
$mailer->addAttachment(JPATH_BASE.DS.'CSV'.DS.$file);
$send =&$mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ' . $send->message;
} else {
echo 'Mail sent';
}
}
($file is the full path of a file zip and $mailto is a my gmail.)
However, when I send mail, I receive the error:
Could not instantiate mail function.
Fatal error: Cannot access protected property JException::$message in /var/www/html/dai/components/com_servicemanager/views/i0602/view.html.php on line 142
What is causing this error?
Please save yourself some sanity and do not try to use Joomla's mailer implementation. Not only is it unreliable as you've experienced, it handles different charsets and HTML content poorly. Just include and use PHPMailer.
Change
echo 'Error sending email: ' . $send->message;
to
echo 'Error sending email:'.$send->get('message');
then run your code again. The error that you get should tell us why it isn't instantiating.
In joomla send a mail with attachment file
$from="noreplay#gmail.com";//Please set Proper email id
$fromname="noreplay";
$to ='admin#gmail.com';
// Set a you want send email to
$subject = "Download";
$message = "Thank you For Downloading";
$attachment = JPATH_BASE.'/media/demo.pdf';
// set a file path
$res = JFactory::getMailer()->sendMail($from, $fromname, $to,$subject, $message,$mode=1,$cc = null, $bcc = null, $attachment);
if($res)
{
$errormsg = "Mail Successfully Send";
}
else
{
$errormsg ="Mail Not Send";
}
after you have check mail in your inbox or spam folder.
mail in spam folder because not proper set email id in from id.
After several years of Joomla development, I recommend using RSFORM PRO by RSJOOMLA to send mail for you after the visitor to your website fills out the form. It is much easier to manage than having to deal with the internal mail server.