how do i send an email through joomla - email

I have a system so folks can register for a class through my Joomla site (I believe it's 3.0). But from there, I would like to send folks an email filling variables from the registration. So something like:
Dear (name), thank you for registering for (class).
This is to remind you your class is tomorrow, (date), at (place).
I believe for the registration, the system uses authorize.net
How can I accomplish this?
Thanks for the help!!

You can use JFactory:getMailer like suggested in the following post. I'm copying here his code example (modified it a bit):
$subject = "Here is the subject of your message.";
$body = "Here is the body of your message.";
$user = JFactory::getUser();
$to = $user->email;
$from = array("me#mydomain.com", "Brian Edgerton");
# Invoke JMail Class
$mailer = JFactory::getMailer();
# Set sender array so that my name will show up neatly in your inbox
$mailer->setSender($from);
# Add a recipient -- this can be a single address (string) or an array of addresses
$mailer->addRecipient($to);
$mailer->setSubject($subject);
$mailer->setBody($body);
# If you would like to send as HTML, include this line; otherwise, leave it out
$mailer->isHTML();
# Send once you have set all of your options
$mailer->send();
That's all there is to it for sending a simple email. If you would like to add carbon copy recipients, include the following before sending the email:
# Add a blind carbon copy
$mailer->addBCC("blindcopy#yourdomain.com");
Another alternative is using JMail::sendMail: http://docs.joomla.org/API17:JMail::sendMail

Fetch the Mail Object:
`$mailer = JFactory::getMailer();`
Set a Sender
$user = JFactory::getUser();
$recipient = $user->email;
$mailer->addRecipient($recipient);
$mailer->setSender($sender);
Recipient
$user = JFactory::getUser();
$recipient = $user->email;
$mailer->addRecipient($recipient);
Create the Mail
$body = 'Body Text';
$mailer->isHtml(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
Sending the Mail
$send = $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ';
} else {
echo 'Mail sent';
}
https://docs.joomla.org/Sending_email_from_extensions

Related

preserve recipients in the sendgrid API

I'm sending an email to multiple recipients using the sendgrid API !
<?php
$email = new SendGrid\Email();
$sendgrid = new SendGrid('API_KEY');
$email
->addTo(array('first#mail.com','second#mail.com'..))
->setFrom('my#mail.com')
->setSubject('Subject goes here')
->setText('Hello World!')
->setHtml('<strong>Hello World!</strong>')
;
$sendgrid->send($email);
Now, I wanna know if there is any way to hide the second email in the "To" header for the first email?
Use the SMTP API for mail-merge type functionality.
Using sendgrid-php, that looks like:
$email = new SendGrid\Email();
$email
->addSmtpapiTo('foo#bar.com')
->addSmtpapiTo('another#another.com', 'Mike Bar')
;
$sendgrid->send($email);
Or for an array:
$email = new SendGrid\Email();
$emails = array("foo#bar.com", "Brian Bar <bar#example.com>", "other#example.com");
$email->setSmtpapiTos($emails);
$sendgrid->send($email);

Bulk email in cakephp using sendgrid

I am using cakePHP to send smtp email with sendgrid. I would like to be able to execute a single send() to multiple recipients and allow sendgrid to use the vars to replace -name- with the names from a array.
In my cakephp controller method I am testing:
protected function fwtEmail() {
$config = 'sendGrid';
$subject = "test";
$Email = new CakeEmail('sendGrid');
$names = array('user#domain.com'=>'John','user2#domain' =>'Paul');
$Email->To($names);
$vars = array('Paul', 'John');
$Email->viewVars(array('name' => $vars));
$Email->from( array('admin#testdomain.com' => 'Jim') );
$Email->subject($subject);
$template = 'bulk';
$Email->template($template, 'default');
$Email->sendAs = 'both';
return $Email->send();
}
Here is a post on the SendGrid blog that does what you describe.
edit: apologies, this appears not to work in the latest cakephp. I'm trying to find a solution for you.

Why might php mail sent but not received unless I manually call the script?

Why might php mail not be received in the second case where twilio is calling the page? Are there characters that might be returned from the api that make the email undeliverable?
1) If I type the URL into the broweser, it attempts to make a wav file in my recordings folder and I get the emails and text messages to all the recipients. The output below is served and the "1" indicates the message was sent.
2) If twilio calls the page and handles the xml, the actual message is recorded to my server, and the output below is served to twilio (which I have verified in my account), but no one receives the email or text. The body of the xml still shows "1" after good bye, indicating the message was sent.
My script:
<?php
date_default_timezone_set('America/New_York');
//copy the remote wav file to my server
$recording = file_get_contents($_REQUEST['RecordingUrl']);
$name = "recordings/".str_replace("+","",$_REQUEST['Caller'])."-".date('Y-m-d-G-i-s',time()).".wav";
$fh = fopen("../".$name, 'w') or die("can't open file");
$stringData = $recording;
fwrite($fh, $stringData);
fclose($fh);
//email the people that need to get the message
$to = "email1#yahoo.com";
$subject = "Voicemail from ".$_REQUEST['From'];
$message = "Click below to listen to your message:\n\r http://domain.com/twilio/".$name;
$from = "email2#domain.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
$to = "email3#domain.com";
mail($to,$subject,$message,$headers);
$to = "9545555555#messaging.sprintpcs.com";
$sent = mail($to,$subject,$message,$headers);
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
<Response>
<Say>Thank you for your message. Good bye.".$sent."</Say>
<Hangup/>
</Response>";
?>
outputs:
<Response>
<Say>Thank you for your message. Good bye.1</Say>
<Hangup/>
</Response>
I just check to see what the contents of each variable in the php mail function are when twilio calls the script to see if there is a character present from a live twilio message. It comes out like this:
$to = 9545555555#messaging.sprintpcs.com
$subject = Voicemail from +19545555555
$message = Click below to listen to your message:
http://domain.com/twilio/recordings/19545555555-2013-10-12-22-57-03.wav
$headers = From:email2#domain.com
If I call the script manually in the browser they are:
$to = 9545555555#messaging.sprintpcs.com
$subject = Voicemail from
$message = Click below to listen to your message:
http://domain.com/twilio/recordings/-2013-10-12-23-04-37.wav
From:email2#domain.com
I tried removing the "+" out of the subject with no success, but when I removed the entire phone number from the subject it works every which way. The emails and texts are delivered appropriately. It makes no sense to me. Maybe its godaddy webhosting messing with my life again.
Perhaps the from string has bad characters that ruin the mail() call, but echo transparently. Try cleaning your string before putting it into mail().
Something like:
$subject= preg_replace("/[^a-zA-Z0-9]+/", "", $_REQUEST['From']);

properly setting email subject line delivered from email form

I have a email form for my website but here is the issue: when i receive an email, the subject line in my inbox shows whatever the user inputted as subject in the form. id like to override that so that whenever an email comes in. the subject in the email header is always "an inquiry from your website". In the message body, sure i don't mind their specific subject they entered but when I receive an email, id like consistency in my inbox.
this is the current code:
<?php session_start();
if(isset($_POST['Submit'])) { if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'xxxxxxxxx';
$fromsubject = 'An inquiry from your website';
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: $nome <$mail>\r\n";
$to = $youremail;
$mailsubject = 'Message received from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is '.$fname.' '.$lname.'
Address: '.$address.'
'.$city.', '.$zip.', '.$country.'
Phone Number: '.$phone.'
E-mail: '.$mail.'
Subject: '.$subject.'
Message:
'.$message.'
|---------END MESSAGE----------|';
echo "Thank you for inquiring. We will contact you shortly.<br/>You may return to our <a href='/index.html'>Home Page</a>";
mail($to, $subject, $body, $headers);
unset($_SESSION['chapcha_code']);
} else {
echo 'Sorry, you have provided an invalid security code';
}
} else {
echo "You must write a message. </br> Please visit our <a href='/contact.html'>Contact Page</a> and try again.";
}
?>
It appears as though you have set a variable called $subject elsewhere.
$subject = $_POST['subject'];
and then use that same variable to send your mail.
mail($to, $subject, $body, $headers);
Try creating another variable for the second use or changing it prior to suit your needs.

PHP mail to variable

I've searched and searched for something similar, but i think i'm not doing it right. So i will ask a question. This is very basic. My problem is as follows:
I have a multi-page form, consisting of 4 pages + 1 preview page. On the preview page, upon submitting i want the entire form data to be sent to 2 different mail adresses. One standard, and the other one, the one that the user has submitted.
So i have:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<?php
$email_from = 'mail#company.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "yourname#yourwebsite.com, $email /n";
$headers = "From: Company";
mail($to,$email_subject,$email_body,$headers);
?>
How should I insert the submitted $email variable in order for it to work?
Remove the \n
$to = 'yourname#yourwebsite.com,' . $visitor_email;
According to the mail() function documentation the $to parameter will take a comma-separated list of addresses as you have attempted, but should have no line break at the end.
Also, your variable is $visitor_email, rather than $email.
$to = "yourname#yourwebsite.com, $visitor_email";
You might also consider adding the visitor's email as a CC or BCC rather than the TO address. In that case, add it as a CC or BCC header (separated by \r\n), but you need to be cautious to be sure that the address is an email address and contains no line break characters which could be used for header injection.
// The From should be an email address
$headers = "From: company#example.com\r\n";
$headers .= "CC: $visitor_email;