Jump to content

Problem with sending mail with PEAR (Mail/mime.php)


wehappyfew

Recommended Posts

Hello to all out there!

this is my first post,so my question may sound a bit simple. :]

I am studying PHP and MySQL and I tried to make a mailing form based on a mysql database.

 

My problem occured when I tried to use the PEAR mail object.

 

Here is my code:

 

// THE INCLUDED FILES

require_once ("attach_file.php"  );

require_once ("Mail.php"        );

require_once ("Mail\mime.php"  );

 

//THE VARIABLES TAKEN FROM THE HTML FORM OR JUST CREATED FOR THE CONSTRUCTION OF THE EMAIL

$my_email      = "something@gmail.com";

$email_subject = mysql_real_escape_string(trim( $_POST['email_subject']),$server_connect );

$email_body    = mysql_real_escape_string(trim( $_POST['email_body']  ),$server_connect );

 

 

$attached_file = $destination ;    // the $destination variable comes from the copy() function in attach_file.php

$username      = "the_username@gmail.com";

$password      = "the_password";

$host          = "smtp.gmail.com";

 

$attach        = new Mail_mime();

$attach -> addAttachment($attached_file);

$email_body    = $attach->get();

 

$extraheaders = array('from'=>$my_email,'to'=>$email_etaireias,'subject'=>$email_subject,'Bcc'=>$email_etaireias);

$headers      = $attach -> $headers($extraheaders);  // HERE GIVES ME AN ERROR!!! -->Fatal error: Method name must be a string

 

$smtp_info    = array('host'=>$host,'auth'=>TRUE,'username'=>$username,'password'=>$password);

$smtp          = Mail::factory('smtp',$smtp_info);

 

 

//loop through every single line of the database until there are no more lines with data

//and store each line in 3 different variables that i can use

while ( $row = mysql_fetch_array($result) )

{ $onoma_etaireias = $row['onoma_etaireias'];

  $email_etaireias = $row['email_etaireias'];

  $website_etaireias = $row['website_etaireias'];  }

 

//construct the mail function .  The @ is supressing the errors created .remove it and they will be shown.

$mail = @$smtp->send($email_etaireias,$headers,$email_body);

 

 

 

As i searched here and there for a solution, i found that it has something to do with the way the mail-mime object creates the body of the email . I also tried to find a solution from the PEAR documentation.

do i create the headers someway wrong?????

 

Link to comment
Share on other sites

I'm sorry!

Let me repost it then hopefully right this time.

 

 

 

 

Here is my code:

// THE INCLUDED FILES
require_once ("attach_file.php"   );
require_once ("Mail.php"        );
require_once ("Mail\mime.php"   );

//THE VARIABLES TAKEN FROM THE HTML FORM OR JUST CREATED FOR THE CONSTRUCTION OF THE EMAIL
$my_email      = "something@gmail.com";
$email_subject = mysql_real_escape_string(trim( $_POST['email_subject']),$server_connect );
$email_body    = mysql_real_escape_string(trim( $_POST['email_body']   ),$server_connect );


$attached_file = $destination ;     // the $destination variable comes from the copy() function in attach_file.php
$username      = "the_username@gmail.com";
$password      = "the_password";
$host          = "smtp.gmail.com";

$attach        = new Mail_mime();
$attach -> addAttachment($attached_file);
$email_body    = $attach->get();

$extraheaders = array('from'=>$my_email,'to'=>$email_etaireias,'subject'=>$email_subject,'Bcc'=>$email_etaireias);
$headers       = $attach -> $headers($extraheaders);   // HERE GIVES ME AN ERROR!!! -->Fatal error: Method name must be a string

$smtp_info     = array('host'=>$host,'auth'=>TRUE,'username'=>$username,'password'=>$password);
$smtp          = Mail::factory('smtp',$smtp_info);


//loop through every single line of the database until there are no more lines with data
//and store each line in 3 different variables that i can use
while ( $row = mysql_fetch_array($result) )
{ $onoma_etaireias = $row['onoma_etaireias'];
  $email_etaireias = $row['email_etaireias'];
  $website_etaireias = $row['website_etaireias'];   }

//construct the mail function .  The @ is supressing the errors created .remove it and they will be shown.
$mail = @$smtp->send($email_etaireias,$headers,$email_body);

 

As i searched here and there for a solution, i found that it has something to do with the way the mail-mime object creates the body of the email . I also tried to find a solution from the PEAR documentation.

do i create the headers someway wrong?????

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.