I have an application built in CodeIgniter. I needed some help with the following email related tasks. Please note all emails will require SSL.
1) Send email to congratulate and welcome the user to the site
2) Send an email to confirm a user account has been deleted should they choose to leave.
3) Send an email to alert the user for a request sent to them from another user.
4) Set up and send an email for "forgot username" and last but not not least
5) Send an email to reset password in case the user can't remember how to login.
Thanks for your help, appreciate it.
function signup(){
$data = array(
'sign_up_mail'=>'Welcome and thanks for joining...'
);
$htmlMessage = $this->parser->parse('user/email/signup_html', $data, true);
$txtMessage = $this->parser->parse('user/email/signup_txt', $data, true);
#send the message
$this->email->from('test#gmail.com', 'test app');
$this->email->to($this->input->post('email_address'));
$this->email->subject('Account Registration');
$this->email->message($htmlMessage);
$this->email->alt_message($txtMessage);
$this->email->send();
}
Would you use this listed below as the method for changing the message within the various emails?
data['message'] = "Hey there, you've got a follower request!";
$email = $this->load->view('email/template', $data, TRUE);
I presume this method works for simple things like user welcome and alerts etc. How would I go about connecting a process to resetting a username/password or confirming a deletion? How do you connect the email process with manipulating data in the db?
From your question, I think you are looking for some kind of authentication related tasks. If so, there is an authentication, library in codeigniter, that provides complete authentication system. Have a look, it it is useful to you. http://konyukhov.com/soft/tank_auth/
Related
I am developing password reset api on backend using Laravel 4.2. It is quite obvious that emails are not sending out if I embed http url . Normal email are sending out properly. Here is how I send email
Laravel Function
Mail::queue('emails.auth.confirm_password',$detail,function($message) use ($email)
{
$message->from('abc#gmail.com', 'Test');
$message->to($email)
->subject('Verification');
});
emails.auth.confirm_password.php
<p>We got a request to reset your Gurilla password. </p>
Reset Password
<p>If you ignore this message, your password won't be changed</p>
I tried many alternatives with no luck. I believe sth weird going on. Might some expert help :-). thanks
I am currently using a function called send:
public function send(){
if ( !empty($this->request->data) ) {
$email = new CakeEmail('default');
$email->from(array($this->Auth->user('email') => $this->Auth->user('username')))
->to(array('helpdesk#example.com'))
->subject($this->request->data['Ticket']['subject'])
->send(array($this->request->data['Ticket']['issue']));
$this->Session->setFlash('Email Sent Successfully', 'default', array('class' => 'message update span9'));
$this->redirect(array('action' => 'index'));
}
to Send emails to our helpdesk and deposit them into their database. All is working EXCEPT the FROM always shows the username/email address from the configuration options. It is not masking the email with the users email.. I need this to happen so that we know who is having the support issue.
Does anyone have a suggestion here on what to do?
*Addition
This is an intranet application and thus we have an authenticated GENERIC USER using smtp settings. This is not spamming, we just want to know which user the Help Desk ticket came from when inserting to the DB.
Why are you using the Config default anyway?
If you use $email = new CakeEmail();, does the email sent references the Authenticated User email info.
Also, you should always use $email->sender('support#yourcompany.com', 'Your Company Support');. This ensures that if there is an issue the problem get redirected to you and not the user, your app is sending an email on his/her behalf.
I have that setup in my account and it works just fine. To Mark's point, it may not be legal (although, that does not seem to be your issue), but I know it is possible as I have currently a system setup that works with whatever email I want. I do not use any Config and also I do not use any SMTP
I'm getting this error when trying to send an email using swiftmailer and the sendgrid smtp
Fatal error: *Uncaught exception 'Swift_TransportException' with message 'Expected response code 250 but got code "", with message ""'*
Here's my code :
$hdr = new SmtpApiHeader();
// Set all of the above variables
$hdr->addTo($toList);
$hdr->addSubVal('-name-', $nameList);
$hdr->addSubVal('-time-', $timeList);
// Specify that this is an initial contact message
$hdr->setCategory("initial");
// The subject of your email
$subject = 'Example SendGrid Email';
// Where is this message coming from. For example, this message can be from
// support#yourcompany.com, info#yourcompany.com
$from = array('no-reply#mupiz.com' => 'Mupiz');
$to = array('antonin#noos.fr'=>'AN',"antonin#mupiz.com"=>"AN2s");
$text="Hello -name-
Thank you for your interest in our products. We have set up an appointment
to call you at -time- EST to discuss your needs in more detail.
Regards,
Fred, How are you?
";
$html = "
<html>
<head></head>
<body>
<p>Hello -name-,<br>
Thank you for your interest in our products. We have set up an appointment
to call you at -time- EST to discuss your needs in more detail.
Regards,
Fred, How are you?<br>
</p>
</body>
</html>
";
// Your SendGrid account credentials
$username = 'XXXX';
$password = 'XXXX';
// Create new swift connection and authenticate
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 25);
$transport ->setUsername($username);
$transport ->setPassword($password);
$swift = Swift_Mailer::newInstance($transport);
// Create a message (subject)
$message = new Swift_Message($subject);
// add SMTPAPI header to the message
// *****IMPORTANT NOTE*****
// SendGrid's asJSON function escapes characters. If you are using Swift Mailer's
// PHP Mailer functions, the getTextHeader function will also escape characters.
// This can cause the filter to be dropped.
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $hdr->asJSON());
// attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
// send message
if ($recipients = $swift->send($message, $failures))
{
// This will let us know how many users received this message
// If we specify the names in the X-SMTPAPI header, then this will always be 1.
echo 'Message sent out to '.$recipients.' users';
}
// something went wrong =(
else
{
echo "Something went wrong - ";
print_r($failures);
}
An idea ?
Thanks
There could be a number of things causing this. The most likely one is that your server has connecting to external hosts turned off. Other possibilities are that you're using an old version of PHP that has an openSSL error or that you're being rate limited by something.
You should take a look at this question for details on the external host issue: send mails via sendgrid
On a separate note, you should use the SendGrid PHP library if you want to send emails using SendGrid. It addresses a whole bunch of subtle nuances with Swift and sending in general. Also, it gives you access to the HTTP API in case you can't use SMTP for whatever reason.
https://github.com/sendgrid/sendgrid-php
Full Disclosure: I work as a developer evangelist for SendGrid and work on the PHP library from time to time.
for sendgrid might be two resons:
you may have the authentification data wrong
your account might still be provisioned, so you must wait a bit for it to be fully activated
so
check all the autentification data from app/config/mail.php to match with the data from https://sendgrid.com/docs/Integrate/index.html
check also not the have a top message/notification on your sendgrid account like:
Your account is still being provisioned, you may not be able to send
emails.
You will also receive this error if your account is frozen for billing reasons (e.g. lapsed credit card expiry date).
Note: SendGrid doesn't drop the message(s), they hold them until your billing issue is resolved then process them even when this error is returned.
When a user subscribes to my newsletter via their email address, using php, how would I send them an 'Activation Link' via email to confirm it is their email address and not a fake one.
so at the moment I have
PHP:
<?php
$to = "recipient#example.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>";
}
?>
I guess i would change the $body to this:
$body = "Please click the link to activate your email \n
http://www.activationlink.com?";
How would I make it so that if a user clicked that link it would add their details to the Mysql database recognising they are a legitimate subscriber?
Any help or suggestions appreciated. Thanks
Quick google search result
http://www.learnphponline.com/scripts/email-activation-for-php-forms
basically you need to create a subscriber table and have a boolean flag call verified, of coz store the email address in that table
ok i would try to suggest you some thing which happens while signup on most of sites today.
what happens is that when you enter your user name and password it says
"An email is sent to your location.....(something like this)" what we do is that before sending email we save that username and password in the DB but make there status inactive.
So when users click the link and they get the relevent site, all needed then is to verify the code and change status.
So some what similar you have to add the email to your DB and then send some email. In that case it will be easy for you handle your current problem.
Use the http://en.wikipedia.org/wiki/Message_authentication_code (MAC) approach. You should have a secret key. Use the key and user's email to generate SHA1 hash. Then produce an activation link which includes user's email and the hash. After you receive a click from the link, you do the same - use the same secret key, take the email from the link, generate hash and compare it with provided in the link. If it does match, then it means the e-mail address is confirmed.
Also, together with email you could include some more info (e.g. timestamp to make links expire-able), all info could be authenticated with the MAC approach.
You don't need store any information in a database, as in answer from #Tommy.
I wanna subscribe my website newsletter members to my Google Group automatically.
I try send email to mygroupname+subscribe#googlegroups.com with subject & body "subscribe" by PHP Mail function from user email. but not any result and subscription resquest in my group.
$phpMailSender = new PHPMailer();
$phpMailSender->CharSet = "UTF-8";
foreach($users as $user) {
$phpMailSender->ClearAddresses();
$phpMailSender->From = $user['email'];
$phpMailSender->FromName = $user['email'];
$phpMailSender->AddReplyTo($user['email']);
$phpMailSender->addAddress('mygroupname+subscribe#googlegroups.com');
$phpMailSender->Subject = 'subscribe';
$phpMailSender->Body = 'subscribe';
$result = $phpMailSender->send();
if($result)
echo "Subscription email Sent for user# " . $user['email'] . "\n";
else
echo "Subscription email failed for user# " . $user['email'] . "\n";
ob_flush();
flush();
}
Can any one help me!
Whilst looking at a question in the hMailServer forum.
The fellow there gives some ideas on how to do this (albeit, no code), but there are good considerations.
But there is a bit more involved than just subscribing the user to the list. You also need to validate the email address the user provides so that people don't enter other people's email addresses. This would be done by sending an email to the user and asking him to confirm his subscription. When he clicks the link to confirm, he goes to your webpage that is keyed to a database entry somewhere, and then the email gets added to the list in a manner that you are attempting.
But check out the link I provide above for a few more considerations.
Here is another similar thread.
As for code, there is a snippet here.
This thread also has some php code, similar to yours - you should look at this.