Jump to content

Recommended Posts

Got this script on my webpage "www.******.com/mail.php".

 

This is the script:

<?php
$to = "xxxxxx@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>

 

 

And when I visit the page, an e-mail gets sent there. But I have a C# program and I want to change &to, &subject and &body in the PHP script.

 

I have this at the moment:

private void button2_Click(object sender, EventArgs e)
{
try
{
WebClient client = new WebClient();


client.DownloadString("http://xxxxxx/mail.php?to=" + "&to={xxxxxx@gmail.com}" + "&subject={Test}" + "&body={Test}");
client.Dispose();
}
catch (Exception)
{
MessageBox.Show("An error occured loading the scripts, restart it again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);

}


}

 

You see, I try to change &to={xxxxxx@gmail.com} and the others, but still the original message gets sent!

The point of this code is, that the C# script will send an e-mail through mail.php. Please help, I would appreciate your time.

Link to comment
https://forums.phpfreaks.com/topic/274894-simple-mail-script/
Share on other sites

Seeing as you're always assigning values, and static values at that, in the PHP script. This is the expected behaviour.

 

Same way that you'd expect this function to always give you "test", no matter what you called it with:

private string function  (string message) {
   message = 'test';
   return message;
}

 

In other words: If you want to be able to change some of those values, you'll need to use the $_GET superglobal. Use isset () and empty () to check if the indices in question have been set.

 

PS: If you do this, you need to secure your PHP script somehow. Otherwise anyone who has access to it (which is everyone, if it's available over the internet) will be able to use this to spam whomever they like.

Link to comment
https://forums.phpfreaks.com/topic/274894-simple-mail-script/#findComment-1414760
Share on other sites

I'm kind of new to this, I tried:

<?php
$to = $_GET["to"];
$subject = $_GET["subject"]
$body = $_GET["message"]
if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
?>

 

and:

 

try
           {
               WebClient client = new WebClient();


               client.DownloadString("http://xxxx.nxxne.net/mail.php?" + "&to={xxxx@gmail.com}" + "&subject={Yxe}" + "&message={Test220}");
               client.Dispose();
           }
           catch (Exception)
           {
               MessageBox.Show("An error occured loading the scripts, restart the hack again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);

           }

 

But doesent work..

Link to comment
https://forums.phpfreaks.com/topic/274894-simple-mail-script/#findComment-1414837
Share on other sites

Define "doesn't work", are any errors received?

This bit of code should put you on the right path:

 

WebClient client = new WebClient();
string url = String.Format("http://www.domain.com/mail.php?to={0}&subject={1}&message={2}", "email@email.com", "recipient@email.com", "message");
client.DownloadString(url);
// rest of code

Link to comment
https://forums.phpfreaks.com/topic/274894-simple-mail-script/#findComment-1414845
Share on other sites

Thanks for the code, I used that but still no e-mail gets sent like before. I think the error is in mail.php. When I go to mail.php page then:

Parse error: syntax error, unexpected T_VARIABLE in /home/a8672447/public_html/mail.php on line 4

 

Error is on line 4? This is code:

<?php
$to = $_GET["to"];
$subject = $_GET["subject"]
$body = $_GET["message"]
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>

Edited by mailman022
Link to comment
https://forums.phpfreaks.com/topic/274894-simple-mail-script/#findComment-1414858
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.