Error writing some custom PHP (is 'require' allowed?)

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
anthony
Forum Members
Forum Members
Posts: 37
Joined: Thu Jun 22, 2006 12:50 am

Error writing some custom PHP (is 'require' allowed?)

Post by anthony »

I am going to creating a custom form using phpmailer that will send out an email to the appropriate office selected in a drop-down.

Now I went into config.php and set use_smarty_php_tags = true; and then got started on my template that will hold the form.  Here is my code:

Code: Select all

{php}
echo 'Test1';
############## EMAIL LEADER ######################
// generate email
require("/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
echo 'Test2';

$mail->From = 'test@test.com';
$mail->FromName = 'Test';
// FOR TESTING
$mail->AddAddress("test@test.com", "Test");
$mail->Subject = "Test request";
// FOR TESTING
$mail->Body    = "\nTesting a request from the web site.";

if(!$mail->Send())
	{
	   echo "Message could not be sent. Please contact <a href=\"mailto:test@test.com\">Test</a>. <p>";
	   echo "Mailer Error: " . $mail->ErrorInfo;
	   exit;
	}
// comment out below line for live version
echo "Message has been sent";

{/php}
Now it seems that as soone as it hits "require("/phpmailer/class.phpmailer.php");" nothing happens.  For example I do not see the text "Test2" that I entered just to see where I was having the problem, no email ends up getting sent but no error or confirmation gets written to the screen either.

I'm wondering, am I allowed to use require inside of a smarty template file?  Also, is this the best way to do this or should I be going about this another way?

Many thanks in advance.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Error writing some custom PHP (is 'require' allowed?)

Post by Dee »

anthony wrote: is this the best way to do this or should I be going about this another way?
The recommended way is to use a User Defined Tag (UDT).

Regards,
D
anthony
Forum Members
Forum Members
Posts: 37
Joined: Thu Jun 22, 2006 12:50 am

Re: Error writing some custom PHP (is 'require' allowed?)

Post by anthony »

That works for me.

Are there any limitations in creating my own tag?  As I said, it seems that all the custom code that I entered into the body of the template isn't being parsed.  I am just looking for something that will parse for sure and of course is recommended.

Thanks.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Error writing some custom PHP (is 'require' allowed?)

Post by Dee »

There are no real limitations in using your own PHP. It's probably a include error because of the relative path you're using, try:

Code: Select all

$gCms = $GLOBALS['gCms'];
require($gCms->config['root_path'] . "/phpmailer/class.phpmailer.php");
or

Code: Select all

$gCms = $GLOBALS['gCms'];
require(cms_join_path($gCms->config['root_path'], 'phpmailer', 'class.phpmailer.php'));
Regards,
D
Post Reply

Return to “CMSMS Core”