• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeIgniter $this->email->attach();

#1
[eluser]44kyle[/eluser]
Hi,
I am building a page for a website where users can go and apply online for a job. Once they fill out the form, it sends an email off with an attached resume, cover letter, and job application.

public function sendAppEmail()
{
$err = null;
$this->loadAppValidation();

if ( ! $this->validation->run() )
{
$err = $this->validation;
}
else
{
$this->load->library("ffi_captcha", $this );

if ( ! $this->ffi_captcha->checkWord( "word_check") )
{
$this->validation->word_check_error = "<div class=\"error_msg\">Security number did not match. Please try again.</div>";
$err = $this->validation;
}
else
{
$this->load->library( "email" );
$this->email->from( "[email protected]" );


$this->email->to( "[email protected]" );
//$this->email->to( "[email protected]" );

$this->email->subject( "Application submitted by " . $_POST["name"] . " on costelloco.com" );

$msg =
"Personal Information: " . "\n" . "\n" .
"Name: " . $_POST["name"] . "\n" .
"City: " . $_POST["city"] . "\n" .
"State: " . $_POST["state"] . "\n" .
"Zip: " . $_POST["zip"] . "\n" .
"phone: " . $_POST["phone"] . "\n" .
"Present Address: " . $_POST["presentaddress"] . "\n" .
"E-Mail: " . $_POST["email"] . "\n" .
"Desired Position: " . $_POST["position"] . "\n" .
"Desired Start Date: " . $_POST["startdate"] . "\n" .
"Desired Salary: " . $_POST["salary"] . "\n" . "\n" .
"General Information: " . "\n" .
"Projects of Special Study/Research work or special training skills: " . $_POST["specialstudy"] . "\n" . "\n" .
"Employment History: " . "\n" .
"Employer: " . $_POST["employer1"] . "\n" .
"Position: " . $_POST["position1"] . "\n" .
"Employer Address: " . $_POST["address1"] . "\n" .
"From: " . $_POST["from1"] . " to " . $_POST['to1'] . "\n\n" .
"Employer: " . $_POST["employer2"] . "\n" .
"Position: " . $_POST["position2"] . "\n" .
"Employer Address: " . $_POST["address2"] . "\n" .
"From: " . $_POST["from2"] . " to " . $_POST['to2'];
$this->email->message( $msg );

//*******lines in question***\\\\\
$this->email->attach($_POST['resume']);
$this->email->attach($_POST['coverletter']);
$this->email->attach($_POST['jobapplication']);
//************************************\\
$this->email->send();
}
}

return $err;
}

The email appears fine in Hotmail and via a pop3 server (without attachments), however, when I add in the three attachments, it throws out all the text in the message body and sends off a blank email.

Any idea what causes this? I did a var_dump on my arrays and there is values in them. Could it be a config issue?

Thanks!

#2
[eluser]Dolrich[/eluser]
The parameter of the attach function requires the file path, not some texts.

If your form is correct, which means it has enctype="multipart/form-data" attribute
And has a field like this &lt;input type="file" name="resume" /&gt;

Change this code from

$this->email->attach($_POST['resume']);

To
$this->email->attach($_FILES['resume']['tmp_name']);

Dolrich

#3
[eluser]44kyle[/eluser]
Ok, that seemed to work. However, it scrambles the attachments into some unrecognizable file, but it attaches something.

#4
[eluser]Dolrich[/eluser]
Ow, you need to move the file first to a folder with the correct file name.
Then attached the currently moved file.

#5
[eluser]44kyle[/eluser]
It works!!!!! Turns out once I renamed the scrambled file to a pdf, I could open it just fine. So I invoked this command before the send function,

move_uploaded_file($_FILES['resume']['tmp_name'], "_client_media/resume.pdf");
$this->email->attach("_client_media/resume.pdf");

Thanks for all your help! I had done some searches on this topic before I posted and none of them solved this issue so I hope this helps someone else too.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.