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";
}
}
?>
Related
I want, that users who register on my site, have to activate their account first, before using it. The problem is, that I don't get any email to my email test account.
Before I start posting a code, could the problem be, that I'm working currently on a local machine with xampp?
Otherwise, here is the code snippet
$random = substr(number_format(time() * rand(),0,'',''),0,10);
$insertMailVerify = $this->db->prepare("INSERT INTO mailverify (mailAddress, token, datetime) VALUES (:mailAddress, :token, :date)");
$insertMailVerify->execute(array(':mailAddress'=>$emailAddress,
':token'=>$random,
':date'=>$date));
$to = $emailAddress;
$subject = "Activating your Account";
$body = "Hi, in order to activate your account please visit http://localhost/FinalYear/activation.php?email=".$emailAddress." and fill in the verification code $random";
if(mail($to, $subject, $body))
{
echo ("<p>Message success</p>");
}
else {
echo ("<p>Message fail</p>");
}
Just in case you wonder where i take $emailAddress from: This is just a code snippet, i already let the software echo the email address, and it's correct. It even goes in the "Message success" if case, but I still can't get any email. What could be the problem?
After submit the form you can use a code or link and send it to the user email id
$message = "Your Activation Code is ".$code."";
$to=$email;
$subject="Activation Code For Talkerscode.com";
$from = 'your email';
$body='Your Activation Code is '.$code.' Please Click On This link Verify.php?id='.$db_id.'&code='.$code.'to activate your account.';
$headers = "From:".$from;
mail($to,$subject,$body,$headers);
echo "An Activation Code Is Sent To You Check You Emails";
Code from TalkersCode.com for complete tutorial visit http://talkerscode.com/webtricks/account-verification-system-through-email-using-php.php
in local host i think the best way is using phpmailer and gmail account
here the tutorial : http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/
It seems your mail server SMTP is not configured correctly....
check the port and IP of SMTP server address.
Try to change you PHP.ini file like this and tell me if it works.
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 465 //if 465 is not working then try 25
If this is not working then there are a lot of tutorials of how to achieve what you are trying to do.
Here is one link: Send email from localhost
Had the same problem, but on linux.
1) Assuming your mail() function is working properly: the problem could be, that email is coming into spam-box (because these localhost mail systems are often marked as spambots, so email services are protecting emails from unverified host).
2) If mail() is not working, its not configured properly, if you follow some tutorial and configure it, which needs like 5 minutes, you will realise why not to use it:)
The best way for you is to use some free or paid smtp service. Very easy, quick and your emails wont be marked as spam. And install PEAR library to send email. Here is an example.
$from = 'from#domain.com';
$to = 'to#domain.com';
$subject = 'subject';
$body = 'Hello!';
$host = 'smtpserver.com';
$port = '25';
$username = 'yourlogin';
$password = 'yourpass';
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if(PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
To your verification code: instead of telling user to write down the verification code, better generate him the link, that he clicks his account gets activated. Something like
http://localhost/FinalYear/activation.php?email=some#email.com&token=79054025255fb1a26e4bc422aef54eb4
on registration page: generate the activation token like md5($email . '_sometext');
on activation page if(md5($_GET['email'] . '_sometext') == $_GET['token']) { activate.. }
please note, that it is just an example, there are 10 ways how it could be done :)
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
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.
I have a problem I have been working on for about a week and can't find an answer. As a preface to this all, I have searched the internet for all sorts of things. There are a lot of answers for this problem, but none seem to be helping me.
I am somewhat new to PHP and a lot of the stuff I am asking for (been using it over the past few months). Let me get to the base of the problem:
I am on a school network with my own server set up in my dorm room. I am creating a website where I need to verify a user's email, but the basic PHP mail() function does not work. I have been told that I will need to use SMTP. So I decided the easiest and cheapest way was with Gmail SMTP. I created an account on Gmail called verify.impressions#gmail.com for this reason. Here is the code.
echo "starting mail sending";
require_once("pear/share/pear/Mail.php");
echo "1";
$from = "PersonA `<someone#gmail.com`>"; $to = "`<someoneElse#email.com`>"; $subject = "Activate your account"; $body = "Hey";
$host = "ssl://smtp.gmail.com"; $port = "465"; //also tried 587 $username = "someone#gmail.com"; $password = "password";
echo "2";
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
echo "3";
$mailer_params['host'] = $host; $mailer_params['port'] = $port; $mailer_params['auth'] = true; $mailer_params['username'] = $username; $mailer_params['password'] = $password;
$smtp = Mail::factory('smtp', $mailer_params);
echo "4";
error_reporting(E_ALL);
echo "5";
if (PEAR::isError($smtp)) { die("Error : " . $smtp->getMessage()); }
echo "6";
$mail = $smtp->send($to, $headers, $body) or die("Something bad happened");
echo "7";
if (PEAR::isError($mail)) {echo($mail->getMessage();} else {echo(Message successfully sent!);}
echo "mail sent hopefully.";
So basically the code just stops at the line:
$mail = $smtp->send($to, %headers, $);
I have tried printing errors, but I just have no idea what to do now. Any tips and help is appreciated. Thanks!!
Use this class: http://www.phpclasses.org/package/14-PHP-Sends-e-mail-messages-via-SMTP-protocol.html
The sample code I use:
require("smtp/smtp.php");
require("sasl/sasl.php");
$from = 'youraddress#gmail.com';
$to = 'some#email.com';
$smtp=new smtp_class;
$smtp->host_name="smtp.gmail.com";
$smtp->host_port='465';
$smtp->user='youraddress#gmail.com';
$smtp->password='XXXXXXXXX';
$smtp->ssl=1;
$smtp->debug=1; //0 here in production
$smtp->html_debug=1; //same
$smtp->SendMessage($from,array($to),array(
"From: $from",
"To: $to",
"Subject: Testing Manuel Lemos' SMTP class",
"Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")
),
"Hello $to,\n\nIt is just to let you know that your SMTP class is working just fine.\n\nBye.\n"));
If you are you using Linux I recommend setting up postfix on your local machine and they asking that to relay the email forwards via an external SMTP service, in your case Gmail.
http://bookmarks.honewatson.com/2008/04/20/postfix-gmail-smtp-relay/
The reason is that your PHP script can timeout incase there's a delay contact Gmail. So you would use Postfix to queue the email on the local server, let the PHP script execution die and trust Postfix to send the email via Gmail.
If you are using Windows, I am sure you can find an equivalent SMTP relay application (should be built as a rough guess).
Many public networks block connections on the SMTP port to remote machines to stop spammers inside their network.
You have two choices:
Find a smtp server that uses a different port than 25
Use the official SMTP server of your school's network. There is always one since people need to send mails out.
I always use this to send mails using gmail as SMTP server.
Very Simple to configure
I working on a form whereby when the user enter in their email account and click on send, an email will be sent to their email account.
I have everything worked out. Just that it doesnt send the email to my account. Anyone have any ideas? Is there a configuration that I left out or something?
This is the sample from my controller:
public function retrieveemailAction(){
$users = new Users();
$email = $_POST['email'];
$view = Zend_Registry::get('view');
if($users->checkEmail($_POST['email'])) {
// The Subject
$subject = "Email Test";
// The message
$message = "this is a test";
// Send email
// Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
// Use if command to display email message status
if(mail($email, $subject, $message, $headers)) {
$view->operation = 'true';
}
} else {
$view->operation = 'false';
}
$view->render('retrieve.tpl');
}
I recommend you use Zend_Mail instead of mail(). It handles a lot of stuff automatically and just works great.
Do you have a SMTP server? Trying to send mail without your own SMTP server could be causing the mail to not be sent.
This is what I use for sending mails using Zend_Mail and Gmail:
In Bootstrap.php, I configure a default mail transport:
protected function _initMail()
{
try {
$config = array(
'auth' => 'login',
'username' => 'username#gmail.com',
'password' => 'password',
'ssl' => 'tls',
'port' => 587
);
$mailTransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Zend_Mail::setDefaultTransport($mailTransport);
} catch (Zend_Exception $e){
//Do something with exception
}
}
Then to send an email I use the following code:
//Prepare email
$mail = new Zend_Mail();
$mail->addTo($email);
$mail->setSubject($subject);
$mail->setBody($message);
$mail->setFrom('username#gmail.com', 'User Name');
//Send it!
$sent = true;
try {
$mail->send();
} catch (Exception $e){
$sent = false;
}
//Do stuff (display error message, log it, redirect user, etc)
if($sent){
//Mail was sent successfully.
} else {
//Mail failed to send.
}
First of all i would switch to using Zend_Mail. Second i would use a real mail account on an smtp server somewhere and send from that. A lot of times there are restrictions on sending from the server itself, but using an actual mail server usually fixes this.
There's a very useful screencast covering Zend_Mail available on ZendCasts
http://www.zendcasts.com/introduction-to-zend_mail/2010/02/
In line $mail->setBody($message);, change it to $mail->setBodyText($message);