Jump to content

PHP Script for email sending


stever_stifler

Recommended Posts

Hi! 

I'm looking for someone who can help me out with PHP script which meant to be launched on FTP server and ought to send some emails based on ready&made email templates written in HTML code. 

 

The basic script looks like this: 

<?php
$receiver = "receiver@gmail.com"; 
$subject = "Subject example"; 
$message = "Message example"; 
$sender = "sender@gmail.com"; 
$header = "From: " . $from;


mail($receiver, $subject, $message, $header);
echo "ok!"; 
?>

What am I supposed to do to run this code with my HTML template and how should I organize files on my FTP server so that the script will be reading all content from HTML template including some graphic files which are used in this template ? 

Link to comment
Share on other sites

Does your ftp server ALSO run php?  As for sending an html email, you need to include some additional headers to make that happen.  As for the template, you will have to work that out as I'm sure you must have some bits of data that you want to insert into the rest of that html, no?  You need to setup your template to incluee the dynamic parts as PHP vars and then just read that in and output into your $message var.

Link to comment
Share on other sites

How do I do it exactly ? 

 

I did try to include entire HTML template sourcecode like that: 

$message = "<div>My entire sourcecode of HTML template </div>";

and unfortunately time and again when I launch the entire file on FTP server, by typing the address of ftp server with slash and the name of this file, I get the exactly same message -> (the sixth line starts with '<head> <xml>')

 

  • 'Parse error: syntax error, unexpected '<' in /home/stevestifler/public_html/script.php on line 6' . 
Edited by stever_stifler
Link to comment
Share on other sites

Why do you keep mentioning FTP Server????  We don't care if it's an ftp server.  We do care if it serves PHP otherwise your script won't run.

 

How about showing us line 6 and the lines around it so we don't have to guess?  Try and make it easier for use to help you!

 

Also - do you have PHP error checking turned on???

Edited by ginerjm
Link to comment
Share on other sites

I don't know why I keep mentioning it. It serves PHP for sure. 

 

The sixth line is the one that starts with <head>

<?php
$receiver = "receiver@gmail.com"; 
$subject = "Subject example"; 
$message = " 
<!DOCTYPE html "-//w3c//dtd xhtml 1.0 transitional //en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <xml>
     <o:OfficeDocumentSettings>
[...]

 

 

Also - do you have PHP error checking turned on???

 

Yes, I do. 

 

The message I get is: 

 

 

 

Parse error: syntax error, unexpected '<' in /home/steve_stifler/public_html/test.php on line 6
Edited by stever_stifler
Link to comment
Share on other sites

It doesn't matter.  You just have to ensure that anything that is meant to be part of $message is included in the string you assign to it. 

 

If you can't handle a simple string assignment at this point you probably shouldn't be tackling this project.  I'm not going to show you cause that's the kind of guy I am.  Figure it out yourself and you will have learned; have me do it and you don't learn a thing.

Link to comment
Share on other sites

Sure, but I'm not asking for the entire code, and giving me the solutions take about... 1 line of code. It's just pity that I came across this forum and I'm wasting my time, listening to people who think they are smart just because there's a newbie member of this community. 

 

Not to mention, that it took you more time to write your silly and how 'enlightening' comment than it would've take to modify a single line of code. 

 

This forum is complete waste of time.  

Link to comment
Share on other sites

Should I use single apostropthe than or what ? 

 

For what it's worth, you are assigning a string to $message on the following line:

$message = "

Since your string starts with a double quote ("), PHP will look for the next double quote to determine where the end of the string is. So basically, PHP thinks this is the string to assign to $message:

" 
<!DOCTYPE html "

...and it's not going to know what to do with the rest, hence the error.

 

 

To prevent PHP from cutting the string off early, you need to use care with double quotes that appear within the [double-quoted] string. You could replace them with single quotes ('), where possible. Or you can escape the double quotes (\"). Or you could even consider using the heredoc or nowdoc syntax. More information about all of these tactics can be found here:

http://php.net/manual/en/language.types.string.php

Edited by cyberRobot
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.