cv sending in email using wp-mail - php

I have uploaded a cv successfully from a career page . Now i want to send this in email.
Upload part
if ($_FILES['filecv']['name'] != "") {
$sqldata['att_ment'] = uploadCVFile($_FILES['filecv']);
} else {
$sqldata['att_ment'] = '';
}
CV is uploaded successfully.
uploadCVFile function
function uploadCVFile($uploadedfile)
{
if (!function_exists('wp_handle_upload'))
require_once (ABSPATH . 'wp-admin/includes/file.php');
$upload_overrides = array('test_form' => false);
add_filter('upload_dir', 'cv_uploads_dir');
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
remove_filter('upload_dir', 'cv_uploads_dir');
if ($movefile) {
return basename($movefile['file']); //$uploadedfile['name'];
} else {
return "";
}
}
path set
function cv_uploads_dir($param)
{
$param['subdir'] = '/cvs';
$param['path'] = $param['basedir'] . $param['subdir'];
$param['url'] = $param['baseurl'] . $param['subdir'];
return $param;
}
now i want to send this in email using the wp_mail function. all other data is sent successfully but i dont know how to deal with the cv.
Mail function
function SendCareers_Email($pst)
{
$to = get_option('career_email');
$from = $pst['e-mail'];
$name = $pst['firstname'];
$cvname="/uploads/cvs/".$sqldata['att_ment'];
$subject = "Applying for the job " . $pst['title'];
$message= "Candidate Name:-" . $name . "<br/>";
$message .= "Job Title Applied:-" . $pst['title'] . "<br/>";
if(!empty($pst['country'])){
$message .= "Country Of Resindency:-" . $pst['country'] . "<br/>";
}
if(!empty($pst['nationlaity'])){
$message .= "Nationlaity:-" . $pst['nationlaity'] . "<br/>";
}
$attachments = array( WP_CONTENT_DIR . $cvname );
if(!empty($pst['mobileno'])){
$message .= "Phone Number:-" . $pst['mobileno'] . "<br/>";
}
add_filter('wp_mail_content_type', 'set_career_html_content_type');
$admin_headers = 'From: '.$name.' <'.$from .'>' . "\r\n\\";
wp_mail($to, $subject,$message , $admin_headers,$attachments);
remove_filter('wp_mail_content_type', 'set_career_html_content_type');
}
function set_career_html_content_type()
{
return 'text/html';
}

In your SendCareersEmail function change this part
$cvname="/uploads/cvs/".$_FILES['filecv']['name'];
$attachments = array(
$cvname
);
When inside a function only global variables or variables you pass into the function (in your case $pst) are available. So either pass in $sqldata to the function SendCVEmail($pst, $sqldata) or use the global call of $_FILES['filecv']['name']

Related

PHP form with multiple attachments "foreach"

$mail_to_send = new PHPMailer();
$mail_to_send->FromName = $author;
$mail_to_send->From = $email;
$mail_to_send->Subject = $subject;
$mail_to_send->Body = "Mittente: ". $author . "\n" . "\n" . "Contatto di
riferimento: " . $contatto . "\n" . "\n" . "Tipo di annuncio: " . $tipo .
"\n" . "\n". $message;
$mail_to_send->AddReplyTo($email);
//contact form destination e-mail:
$mail_to_send->AddAddress('mymail#gmail.com');
foreach ($_FILES['attachment'] as $_allegato){
if ( !$_allegato['attachment']['error'] == 4 ) { //something was send
if ( $_allegato['attachment']['error'] == 0 &&
is_uploaded_file($_allegato['attachment']['tmp_name']) )
$mail_to_send->AddAttachment($_allegato['attachment']['tmp_name'],
$_allegato['attachment']['name']);
else
wp_die('Error: there was a problem with the file upload. Try again
later.');
}
}
Why is my foreach not working? foreach ($_FILES['attachment'] as $_allegato){
I need to send multiple attachments with $mail_to_send but i'm not familiar with php $files.
Thanks.

Send emails to posted email address

Currently, I have a directory website that expiry notices to users. I would like to be able to send these same notices to the registered email address on the directory listings. Currently, the website only sends the email to the post_author.
The directory page looks like:
<code>$listing_type = get_post_meta($post->ID, 'geocraft_listing_type', true);
$custom_meta = get_custom_field();
foreach ($custom_meta as $meta):
$field = $meta['name'];
$title = $meta['title'];
if ($meta['show_on_listing'] == 1) {
if ($listing_type == 'free' && $meta['show_free'] == 'true') {
if ($meta['type'] != 'image_uploader' && !in_array($field, $social_exclude)
) {
if (get_post_meta($post->ID, $field, true)) {
?>
<tr>
<td class="label default"><?php echo $title; ?> </td>
<td><?php
if ($field == 'geocraft_website') {
echo '<a target="new" href="' . get_post_meta($post->ID, $field, true) . '">' . get_post_meta($post->ID, $field, true) . '</a>';
} elseif ($field == 'geocraft_phone') {
echo '<a href=tel:' . str_replace(' ', '', get_post_meta($post->ID, $field, true)) . '>' . str_replace(' ', '', get_post_meta($post->ID, $field, true)) . '</a>';
} elseif ($field == 'geocraft_meta_email') {
echo '<a href=mailto:' . get_post_meta($post->ID, $field, true) . '?Subject=subject here&Body=bodytext>' . get_post_meta($post->ID, $field, true) . '</a>';
} elseif ($meta['type'] == 'multicheckbox') {
echo implode(', ', get_post_meta($post->ID, $field, true));
} else {
echo get_post_meta($post->ID, $field, true);
}
?></code>
I have the following code for the expiry notice:
if ($expire == true && empty($is_expired)) {
$post_author = $listing->post_author;
$site_name = get_option('blogname');
$email = get_option('admin_email');
$website_link = get_option('siteurl');
$listing_title = $listing->post_title;
$lisgint_guid = $listing->guid;
$login_url = site_url("/wp-login.php?action=login");
$listing_user_name = get_the_author_meta('user_login', $post_author);
$message .= "--------------------------------------------------------------------------------\r";
$message .= sprintf(__("Dear %s,", 'geocraft') . " \r", $listing_user_name);
$message .= __("Your listing is expired. We inform you that, if you are interested to reactivate your listing,", 'geocraft') . " \r";
$message .= __("Login in our website and reactivate it.", 'geocraft') . " \r";
$message .= "--------------------------------------------------------------------------------\r";
$message .= sprintf(__("Listing Title: %s", 'geocraft') . " \r", $listing_title);
$message .= "Login On: $login_url \r";
$message .= "--------------------------------------------------------------------------------\r";
$message .= sprintf(__("Website: %s", 'geocraft'), $site_name . "\r");
$message .= sprintf(__("Website URL: %s", 'geocraft'), $website_link . "\r");
$message .= "--------------------------------------------------------------------------------\r";
//$message1 .= "--------------------------------------------------------------------------------\r";
$message1 .= __("Dear Admin,", 'geocraft') . " \r\r";
$message1 .= __("A listing from one of your users got expired and a notification email has been sent to the user.", 'geocraft') . " \r\r";
$message1 .= __("Expired Listing Details are as follows:", 'geocraft') . " \r";
$message1 .= "--------------------------------------------------------------------------------\r";
$message1 .= sprintf(__("User Name: %s", 'geocraft') . " \r", $listing_user_name);
$message1 .= sprintf(__("Listing Title: %s", 'geocraft') . " \r", $listing_title);
$message1 .= "--------------------------------------------------------------------------------\r\r";
$message1 .= __("Kindly, Login to your site for more information:", 'geocraft') . " \r\r";
$message1 .= sprintf(__("Login On: %s", 'geocraft'), $login_url . "\r");
$message1 .= sprintf(__("Website: %s", 'geocraft'), $site_name . "\r");
$message1 .= "Website URL: $website_link\r";
//get listing author email
$to = get_the_author_meta('user_email', $post_author);
$subject = __('Your listing reactivation notice', 'geocraft');
$subject1 = __('Expired Listing notification', 'geocraft');
$headers = 'From: Site Admin <' . $email . '>' . "\r\n" . 'Reply-To: ' . $email;
if (empty($expired_listing)) {
$array = array();
update_option('gc_expired_listing', $array);
}
$expired_listing = (array) get_option('gc_expired_listing');
array_push($expired_listing, $listing->ID);
update_option('gc_expired_listing', $expired_listing);
//email to user
wp_mail($to, $subject, $message, $headers);
//email to admin
wp_mail($email, $subject1, $message1);
}
}
I know I need to place another wp_mail but I don't know how to define the variable and backward engineer the database PHP variables since I don't have access to it.
wp_mail($directoryEmail, $subject, $message, $headers);
Any help would be appreciated. Sorry for the long post. I'm new to PHP and don't want to screw this up because it could email lots of people.
Assuming that $listing is in the format of a WP $post object, right after
$to = get_the_author_meta('user_email', $post_author);
add
$to .= ',' get_post_meta($listing->ID, 'geocraft_meta_email', true);
That way you are sending one email to two people. It would be cleaner to send a total of 3 separate emails, but it's not clear whether or not you have access to the directory listing person's name. You really need database access in order to do this sort of work.
To make sure you don't accidentally email real users, before you make any changes, copy your whole website to a staging/dev site. You can then use phpMyAdmin to change every instance of geocraft_meta_email to your own test email address. I like to use Gmail because if you have an address like myname#gmail.com you can actually email myname+anystringyoulike#gmail.com - that way you still receive the actual emails, but it lets you identify exactly which email came through.

ZEND framework Google Calendar Shutdown - php web app

As of November 17, 2014 Google announced they shutdown the google calendar API v1,v2.
See this link:
http://googleappsupdates.blogspot.com/2014/06/calendar-gdata-api-google-calendar.html
A couple years ago we built a php web form to input data into the calendar with ZEND framework.
With the current code now not working and getting this error.
Error: Expected response code 200, got 403
Forbidden
Error 403
This is very frustrating because we need this application working on the website, its basically the whole point of even visiting the site in the first place.
The php form was pretty simple. Basically a visitor would enter their zip code, then choose a day and time that is displayed from the "availability calendar" on their gmail calendar account. There was also two more custom calendar that was for booked online, and internal booking purposes. Once someone completed the steps including input forms with their contact information and hitting submit the "availability calendar" would be updated on their site as booked and the google calendar itself.
It would also send en email notifying you booked.
I am not personally familiar with ZEND and Google Cal APIv3. I have a level of understanding with php/css/etc but not deep enough to go through the entire upgrade process.
I was hoping maybe it was something pretty easy and someone here on StackOverflow that has a strong knowledge with this material can help me with.
It seems I have read their forums and many, many, many people are frustrated with the shutdown of v1,v2.
Would I need to upgrade the ZEND framework? Currently it is 1.11.3, or can I leave that alone.
I have read that the point of v3 is to make writing the code easier, so maybe this isn't to difficult of a task... Here is the code on the first step.
<?php
function setEnvironment() {
session_start();
date_default_timezone_set('America/New_York');
}
setEnvironment();
function setup() {
set_include_path("/var/www/vhosts/mydomainexample.com/httpdocs/");
require_once("Zend/Loader.php");
Zend_Loader::loadClass("Zend_Gdata");
Zend_Loader::loadClass("Zend_Gdata_ClientLogin");
Zend_Loader::loadClass("Zend_Gdata_Calendar");
}
//////////////////////////////////////////////////
// //
// CONNECT TO GOOGLE CALENDAR //
// //
//////////////////////////////////////////////////
function connect() {
global $service;
$user = "mygmailexample#gmail.com";
$pass = "mypasswordexample";
$serviceName = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $serviceName);
$service = new Zend_Gdata_Calendar($client);
}
//////////////////////////////////////////////////
// //
// CREATE EVENT AND ADD TO CALENDAR //
// //
//////////////////////////////////////////////////
function bookAppointment() {
global $service;
$title = "ONLINE BOOKING: " . $_SESSION["fullName"] . " , " . $_SESSION["townCity"];
$content .= "Name: " . $_SESSION["fullName"] . "\n\n";
$content .= "Requested Time: " . date("l M jS g:i A",$_SESSION["s"]) . " - " . date("g:i A",$_SESSION["e"]) . "\n\n";
$content .= "Home Phone: " . $_SESSION["homePhone"] . "\n\n";
$content .= "Email: " . $_SESSION["emailAddress"] . "\n\n";
$content .= "Address: \n\n" . $_SESSION["streetAddress"] . "\n";
$content .= "" . $_SESSION["townCity"] . " ";
$content .= "" . $_SESSION["zipCode"] . "\n\n";
$content .= "" . $_SESSION["jobDescription"] . "\n\n";
$event = $service->newEventEntry();
$event->title = $service->newTitle($title);
$event->content = $service->newContent($content);
$when = $service->newWhen();
$when->startTime = date(DateTime::RFC3339,$_SESSION["s"]);
$when->endTime = date(DateTime::RFC3339,$_SESSION["e"]);
$event->when = array($when);
$newEvent = $service->insertEvent($event,"http://www.google.com/calendar/feeds/o8d31pro7mbgbi2g93acsluhn8#group.calendar.google.com/private/full");
$eventUri = $newEvent->id->text;
$to = "example#example.com";
$subject = $title;
$message = $content;
$headers = 'From: ' . $_SESSION["emailAddress"] . "\r\n" .
'Reply-To: ' . $_SESSION["emailAddress"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
$to = $_SESSION["emailAddress"];
$subject = "BOOKED:";
$message = "Thank you for booking an appointment with example! We look forward to seeing you and may contact you one more time to confirm before we travel to your location.\n\n" . $content;
$headers = "From: example <example#example.com>\r\n" .
"Reply-To: Lalaland Tan <example#example.com>\r\n" .
"X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
}
//////////////////////////////////////////////////
// //
// GET SCHEDULE AND AVAILABILITY FROM GOOGLE //
// //
//////////////////////////////////////////////////
function getSchedule() {
global $service, $timeSlotsByDay;
$query = $service->newEventQuery();
$query->setVisibility("private");
$query->setProjection("full");
$query->setOrderby("starttime");
$query->setSortOrder('ascending');
$query->setStartMin(date(DateTime::RFC3339));
$query->setStartMax(date(DateTime::RFC3339,(time()+2678400)));
$query->setSingleEvents("true");
$query->setMaxResults(999);
$query->setUser("exampleurl#group.calendar.google.com");
try {
$internalBookings = $service->getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage();
}
$query->setUser("exampleurl#group.calendar.google.com");
try {
$onlineBookings = $service->getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage();
}
$query->setUser("exampleurl#group.calendar.google.com");
try {
$availableSlots = $service->getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage();
}
$timeSlotsByDay = array();
foreach ($availableSlots as $timeSlot) {
$slotStart = strtotime($timeSlot->when[0]->starttime);
$slotEnd = strtotime($timeSlot->when[0]->endtime);
$available = true;
foreach ($internalBookings as $event) {
if ( $available ) {
$bookingStart = strtotime($event->when[0]->starttime);
$bookingEnd = strtotime($event->when[0]->endtime);
if ( ( $bookingStart >= $slotStart ) && ( $bookingStart < $slotEnd ) ) {
$available = false;
}
if ( ( $bookingEnd > $slotStart ) && ( $bookingEnd <= $slotEnd ) ) {
$available = false;
}
if ( ( $bookingStart <= $slotStart ) && ( $bookingEnd >= $slotEnd ) ) {
$available = false;
}
}
}
foreach ($onlineBookings as $event) {
if ( $available ) {
$bookingStart = strtotime($event->when[0]->starttime);
$bookingEnd = strtotime($event->when[0]->endtime);
if ( ( $bookingStart >= $slotStart ) && ( $bookingStart < $slotEnd ) ) {
$available = false;
}
if ( ( $bookingEnd > $slotStart ) && ( $bookingEnd <= $slotEnd ) ) {
$available = false;
}
}
}
$timeSlotsByDay[date("Ymd",strtotime($timeSlot->when[0]->starttime))][] = array("start"=>$slotStart,"end"=>$slotEnd,"available"=>$available);
}
}
//////////////////////////////////////////////////
// //
// STORE FORM DATA IN SESSION //
// //
//////////////////////////////////////////////////
function sessTimeSlot() {
$_SESSION["s"] = $_GET["s"];
$_SESSION["e"] = $_GET["e"];
}
function sessJobDetails() {
$_SESSION["fullName"] = $_POST["fullName"];
$_SESSION["homePhone"] = $_POST["homePhone"];
$_SESSION["emailAddress"] = $_POST["emailAddress"];
$_SESSION["streetAddress"] = $_POST["streetAddress"];
$_SESSION["townCity"] = $_POST["townCity"];
$_SESSION["zipCode"] = $_POST["zipCode"];
$_SESSION["jobDescription"] = $_POST["jobDescription"];
}
?>
you can't use Zend anymore to list, add, delete event. You have to use google api v3.
Here is an example of class you can use to manage events:
Authentification Zend Gdata (403 forbidden)

forgotten / reset password codeigniter issue

I am setting up a forgotten password and reset form. When I send my email. I have 2 issues. One is the unique code is not showing up in URL on when click on link. And the other issue I am having it says Message: Undefined variable: message.
Everything else works fine but just the code not showing up in URL and $message error.
Why is it not picking up my $code in URL. And having error $message?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Forgotten extends MX_Controller {
private $error = array();
public function __construct() {
parent::__construct();
if ($this->user->hasPermissionAccess() == TRUE) {
$this->lang->load('admin/english', 'english');
$this->lang->load('admin/common/forgotten', 'english');
$this->load->library('settings');
$this->load->library('pagination');
$this->load->library('request');
$this->load->library('response');
$this->load->library('document');
} else {
redirect('admin/error');
}
}
public function index() {
$this->document->setTitle($this->lang->line('heading_title'));
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->load->library('email');
$config['protocol'] = 'smpt';
$config['smpt_host'] = 'ssl://squid.arvixe.com';
$config['smpt_port'] = '465';
$config['smpt_user'] = '********'; // Username Blanked Out For Security
$config['smpt_password'] = '******'; // Password Blanked Out For Security
$this->email->initialize($config);
$this->email->from($config['smpt_user']);
$this->email->to($this->request->post['email']);
$subject = sprintf($this->lang->line('text_subject'), $this->settings->get('config_name'));
$this->email->subject($subject);
$code = sha1(uniqid(mt_rand(), true));
$this->load->model('admin/user/users_model');
$this->users_model->editCode($this->request->post['email'], $code);
$message .= sprintf($this->lang->line('text_greeting'), $this->settings->get('config_name')) . "\n\n";
$message .= $this->lang->line('text_change') . "\n\n";
$code = sha1(uniqid(mt_rand(), true));
$message .= site_url('admin/reset/', $code) . "\n\n";
$message .= sprintf($this->lang->line('text_ip'), $this->request->server['REMOTE_ADDR']) . "\n\n";
$this->email->message($message);
$this->email->send();
echo $this->email->print_debugger();
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => '<i class="fa fa-home"></i>' .' '. $this->lang->line('text_home'),
'href' => site_url('common/dashboard')
);
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('heading_title'),
'href' => site_url('common/forgotten')
);
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
$data['action'] = site_url('admin/forgotten');
$data['cancel'] = site_url('admin');
$data['heading_title'] = $this->lang->line('heading_title');
$data['text_your_email'] = $this->lang->line('text_your_email');
$data['text_email'] = $this->lang->line('text_email');
$data['entry_email'] = $this->lang->line('entry_email');
$data['button_reset'] = $this->lang->line('button_reset');
$data['button_cancel'] = $this->lang->line('button_cancel');
return $this->load->view('common/forgotten', $data);
}
public function validate() {
$this->load->model('admin/user/users_model');
if (!isset($this->request->post['email'])) {
$this->error['warning'] = $this->lang->line('error_email');
} elseif (!$this->users_model->getTotalUsersByEmail($this->request->post['email'])) {
$this->error['warning'] = $this->lang->line('error_email');
}
return !$this->error;
}
}
Found issue where the first $message . was it should just be $message no full stop. And for code problem I changed the site_url to base.
$message = sprintf($this->lang->line('text_greeting'), $this->settings->get('config_name')) . "\n\n";
$message .= $this->lang->line('text_change') . "\n\n";
$code = sha1(uniqid(mt_rand(), true));
$message .= base_url('admin/reset') . '/' . $code . "\n\n";
$message .= sprintf($this->lang->line('text_ip'), $this->request->server['REMOTE_ADDR']) . "\n\n";
$this->email->message($message);

PHP Form eMail + write to CSV

I have this form where I wan't people to sign up for receiving free stuff campaign. The form works fine and its send the details to the requested eMail.
Now this form should also write the details to a csv file that we can handle the data more easily.
I use this form:
$value) {
${"".$key} = $value;
}
if (!isset($email)) {
header( "Location: $formurl" );
exit;
}
if ($_POST['services']) {
foreach($_POST['services'] as $value) {
$check_msg .= "- $value\n";
}
}
function is_email($email) {
return ereg("^[^# ]+#[^#]+\.[^# ]+$", $email);
}
function validate_email($email) {
// Create the syntactical validation regular expression
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*#([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
// Presume that the email is invalid
$valid = 0;
// Validate the syntax
if (eregi($regexp, $email))
{
list($username,$domaintld) = split("#",$email);
// Validate the domain
if (getmxrr($domaintld,$mxrecords))
$valid = 1;
} else {
$valid = 0;
}
return $valid;
}
$formurl = "/sticker/index.php" ;
$errorurl1 = "/sticker/error.php" ;
$errorurl2 = "/sticker/error.php" ;
$thankyouurl = "/sticker/success.php#start" ;
$http_referrer = getenv( "HTTP_REFERER" );
// get POST && GET vars to run with 'register_globals off'
//foreach($_GET AS $key => $value) {
// ${"".$key} = $value;
//}
$messageproper =
"============================================================\n" .
"Sticker Request $firstname $lastname\n" .
"============================================================\n\n" .
"KUNDENDATEN\n\n" .
"Vorname: $firstname\n" .
"Nachname: $lastname\n" .
"Firma: $company\n" .
"Strasse: $street\n" .
"Strasse2: $street2\n" .
"PLZ: $zip\n" .
"City: $city\n" .
"Land: $country\n\n" .
"Telefon: $phone\n" .
"eMail: $email\n" .
"Facebook Name: $fbname\n\n" .
"--------------------------------------\n\n" .
"Bemerkung: $comment\n\n" .
"============================================================\n\n" ;
$myFile = "/sticker/sticker.txt";
$fh = fopen($myFile, 'a');
$stringData = "\r\n";
$x=0;
foreach($_POST AS $key => $value) {
$x!=0?$stringData=",".$stringData:'';
$stringData='"'.$firstname.'";"'.$lastname.'";"'.$company.'";"'.$street.'";"'.$street2.'";"'.$zip.'";"'.$city.'";"'.$country.'";"'.$phone.'";"'.$email.'";"'.$fbname.'";"'.$comment.'"'."\r\n";
$x++;
}
fwrite($fh, $stringData);
fclose($fh);
$mailto = 'email#domain.com' ;
$subject = "Free Sticker Campaign: $company - $firstname $lastname";
mail($mailto, $subject, $messageproper, "From: \"$firstname $lastname\" <$email>\nReply-To: \"$lastname\" <$email>\nX-Mailer: chfeedback.php 2.01" );
header( "Location: $thankyouurl" );
exit;
?>
As I said nothing gets written to the CSV File I declared in $myFile.
Would be great if someone could let me know what to do.
Thanks.

Categories