I have been trying to create variables to parse into the email class for sending mails in codeigniter. Assuming I want to send a mail to the logged in user, I decided to create a variable
uemail = $_SESSION['email'];But then when I decided to parse it into the email class as $this->email->to($uemail);, does not send the email to the mail. But then when I use $this->email->to('email#email.com'); the mail is sent to the email correctly so I'm thinking I'm experiencing problem with parsing the variable. Doing $this->email->to($_SESSION['email']); too does not work. Please help me out. Thank you .
I just updated my question with detailed codes. I hope this helps. See below;
<?php
$this->Sendmails_model->sendmail();
$uemail = $_SESSION['email'];
$this->email->to($uemail);
$this->email->subject('Email subject here');
$maildata = array(
'firstName' => $_SESSION['first'],
'content' => 'Email content here'
);
$body = $this->load->view('emails/basic',$maildata,TRUE);
$this->email->message($body);
$this->email->send();
?>
For setting session variables you have to use this syntax,
$this->session->userdata('session_variable');
Looking up the link in #Vickel 's comment, $_SESSION['session_variable'] may also be used in CodeIgniter. Hence no problem with the codes.
From your comment, the issue was with the server receiving the email, hence we may consider this question solved.
Related
Hello guys I am currently working on a registration page on our project Using WORDPRESS where I will send a Confirmation through Email after registration
I am using this Code.. The Code is working right and fine and I also don't see any Error, because if I use it independently without wordpress it is Working. But when I put it inside the wordpress It doesn't send the email at all like in yahoo or gmail? I don't know what is causing the error .
Can you guys give me solution for this?
Sorry for the Bad English.
$peremail = "blablashdjjkas#yahoo.com";
$to = "$peremail";
$subject = "Successfully Registered";
$message = "
Welcome to the Data Portal\n
Thank you very much in trusting Us
Account Detail
Username: $username
Password: $password2";
$header = "From:TITLE Subject \r\n";
$retval = mail ($to,$subject,$message,$header);
But when i use this code outside the wordpress it is working. Don't know what's the error.
BTW the page that I am using is already published online I don't know is there any security issues??
Thank you in advance...
wordpress is using wp_mail function for sending mail.Replace your mail function with wp_mail or you can directly use WP-Mail-SMTP plugin for sending all the mails https://wordpress.org/plugins/wp-mail-smtp/.
I've been trying for a while to get my emails to send using SendGrid. I've set up a test PHP script:
<?php
require_once('../resources/functions/sendgrid/lib/SendGrid.php');
SendGrid::register_autoloader();
require_once('../resources/functions/unirest/lib/Unirest.php');
$sendgrid = new SendGrid('my_username', 'my_password');
$sendgrid_email = new SendGrid\Email();
$sendgrid_email->addTo('my_email#gmail.com')->
setFrom('Name <noreply#my_domain.co.uk>')->
setSubject('Name | Test Mail')->
setText("TEST MESSAGE");
$sendgrid->smtp->send($sendgrid_email);
echo 'mail sent';
?>
I've tried this using both the web and smtp methods, both methods get to the "mail sent" echo, yet neither actually appear in my inbox, and when I check my SendGrid account I still have 0 sent emails.
EDIT:
Ok, so I got it working. Removed the "name ", changed it to just "noreply#my_domain.co.uk". However, I want to define the name using the first method - any way of doing this?
ANOTHER EDIT:
Alright, Nick Q's answer fixed the rest of the issues I was having. And for anyone who is wondering, the way you set a from name (i.e Example ) is by having setFrom as just the email [setFrom("noreply#example.com")] and then using setFromName [setFromName("Example")].
Call SendGrid::register_autoloader(); after also requiring Unirest.
Otherwise your script looks good.
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/
This question should have a simple, simple answer, but I just can't seem to get it working. Here's the scenario:
I created a php page -> this one: http://adianl.ca/pages/member_application.php. Once the form is completed, it proceeds to http://adianl.ca/pages/member_application_action.php, puts the data into a MySQL db, & thanks the user for their interest. Anyway, the form works perfectly, except for one little thing: whenever someone fills out that form, I want an email to be sent to sbeattie#adianl.ca, informing them that the form was filled out, & the email would include the form components. The problem is, I can NOT get an email to be sent to that address, or any address truth be told. Having a php page send an email should be a simple thing to do, but it's really baffling me.
Can anyone help me with this? This particular problem has been troubling me since yesterday, & if anyone can help me with this...man, thank you soooooo much.
JP
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.adianl.ca"; // SMTP server $mail->From = "webadmin#adianl.ca";
$mail->FromName = "Web Administration [ADIANL]";
$mail->AddAddress("sbeattie#adianl.ca");
$mail->AddCC("justinwparsons#gmail.com"); the #messageBody variable is just a string
If you want to have the email sent using the server's sendmail client, you can use mail.
If you want it to use another mail server, there are extensions to connect to an SMTP server. I use PHPMailer.
If mail doesn't work, it could be that the server is not set up to send email, or it could be that the mail server is rejecting emails sent from php, amongst other reasons.
this code can also be used to email in php so have a look, you can find many more examples of emailing in php look around
?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'm trying to sends mails in PHP. The code I used for sending a mail in CakePHP is given below. I get the message 'Simple Email Sent' in my web page but the mail is not delivered to my inbox. Am I missing something?
The values in the to, subject and link fields are set with the values entered in the user interface.
$this->set('to',$this->params['form']['to']);
$this->set('subject',$this->params['form']['subject']);
$this->set('link',$this->params['form']['link']);
$this->Email->to = to;
$this->Email->subject = subject;
$this->Email->from = 'someperson#somedomain.com';
$this->Email->delivery= 'mail';
$this->Email->sendAs='text';
$this->Email->template = 'simple_message';
//$this->Email->send(link);
if ( $this->Email->send(link) ) {
$this->Session->setFlash('Simple email sent');
} else {
$this->Session->setFlash('Simple email not sent');
}
On a Linux system, you'll probably have a sendmail script installed already, and PHP will use that. If this is what you have and it's not working, then I'd look for mail configuration problems in your Linux system itself.
On a Windows system, you'll need to configure the SMTP server you want PHP to send mail to. The normal way to do this is in php.ini. The instructions for this are here.
Unless you have set Email->delivery this should be the same for CakePHP - it should default to whatever PHP uses.
Note: If you are using your own Linux install, it could just be that your ISP is blocking port 25, which your mail server is using. In that case you'll need to configure linux to route email to your ISP's email server. Maybe this will help?
Since when is 'to' (line 4) a valid destination email address?
You need to use variable syntax for setting to 'to' line, and the 'subject' line. Those lines should read
$this->Email->to = to;
$this->Email->subject = subject;
Also, I believe there is an attribute in the Email component called error (I cannot find it in the documentation currently) that will help you debug. This may not be totally correct; I use the Email component with SMTP, and there is an attribute that gets set by the Email component called smtpError. I believe there is one called error that you can use to check for an error -- it should contain code that will tell you where your problem lies.
In case that's an incorrect statement, you can always do a var_dump( $this->Email ); after you try to send an email. That will dump the entire contents of the object, so you can see if you have set attributes correctly, and it should help you find out what the error attribute is named.