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      = "[email protected]";

$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      = "[email protected]";

$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?????

 

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      = "[email protected]";
$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      = "[email protected]";
$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?????

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

 

Function/method names do not start with a $.  Only variables.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.