48 users online (1 members and 47 guests)  


  Results 1 to 6 of 6

Related

  1. cookies needed for newsletter opt in    Forum: Javascript Forum
    Replies: 0
  2. sign out    Forum: Myspace Forum
    Replies: 0
  3. Creating a Newsletter Group    Forum: Website Scripts Forum
    Replies: 1
  4. Replies: 1
  1. #1
    BigAl75's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    2

    CGI newsletter sign-up form

    I'm fairly new to CGI forms, and the company I work for wants to use one for a newsletter sign-up. I made one for another department where people can register for a short course we're giving, and it worked fine. I tried to edit it to use for the newsletter sign-up, and I keep getting a 500 error, and have no idea why. I've checked and double-checked about a dozen times, but I can't find what I did wrong.

    I'm hoping someone here can help me out with it.

    cgi code:

    Code:
    #PATH-TO-PERL#
    print "Content-type: text/html\n\n";
    
    # Set the variables
    $mailprog = '/usr/sbin/sendmail';
    $recipient = 'MYEMAIL';
    $date_command = "/usr/bin/date";
    $date = `$date_command`;
    
    # Get the input
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    
    # Split the name-value pairs
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    
    # Un-webify plus signs and %-encoding
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ s/<!--(.|\n)*-->//g;
    
    if ($allow_html != 1) {
    $value =~ s/<([^>]|\n)*>//g;
    }
    
    $FORM{$name} = $value;
    }
    
    ####################### send the mail ###############################
    
    open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
    
    print MAIL <<STOP;
    
    To: $FORM{"to"}
    From: $FORM{"feedback_provider_email"}
    Subject: $FORM{"formname"}
    Submitted: $date
    ===================================================
    
    APP FEEDBACK FORM
    
    ===================================================
    
    FEEDBACK PROVIDER CONTACT INFORMATION
    
    Form of Address: $FORM{"newsletter_address_title"}
    
    Name: $FORM{"newsletter_firstname"} $FORM{"newsletter_middlename"} $FORM{"newsletter_lastname"}
    
    Company Name: $FORM{"newsletter_company"}
    
    Company Email: $FORM{"newsletter_email"}
    
    Company Website: $FORM{"newsletter_website"}
    
    ====================================================
    
    STOP
    
    close MAIL;
    
    ################## return html ##########################
    
    print "Content-type:text/html\n\n";
    
    #Thank the user. Anything else you print here will appear on the htmlpage.
    
    print '<title>APP Feedback Form</title>';
    
    print '<BODY BGCOLOR=#FFFFFF>';
    print '<BIG>Form successfully sent.</p>';
    print 'We will respond promptly.</BIG><p>';
    
    print '<A HREF="http://www.pmiapp.com/news/index.html">Back to the news page</A>'
    html:

    Code:
    <form action="path-to-script" method="POST">
    	<div>
    		<p>Please complete this form to sign-up for the PMI newsletter. When finished, press the submit button at the end of the page.</p>
    		<p>You can preview the newsletter <a href="newsletter_April_2007/preview_April_newsletter.pdf" target="_blank">here</a>.</p>
    		<p><strong>Registration Form:</strong></p>
    	</div>
    	<!-- Start Name Forms -->
    		<div style="padding: 10px;">
    			<input type="hidden" name="to" value="MYEMAIL" />
    			<input type="hidden" name="formname" value="PMI Newsletter Sign-Up" />
    			<div style="padding: 10px;">
    			<strong>Title:</strong> <select name="newsletter_address_title" size="1">
    			<option selected="selected">--</option>
    			<option>Mr.</option>
    			<option>Ms.</option>
    			<option>Dr.</option>
    			</select>
    		</div>
    		<div style="padding: 10px;">
    			<strong>First Name:</strong> <input type="text" size="17" maxlength="100" name="newsletter_firstname" />
    		</div>
    		<div style="padding: 10px;">
    			<strong>MI:</strong> <input type="text" size="4" maxlength="1" name="newsletter_middlename" />
    		</div>
    		<div style="padding: 10px;">
    			<strong>Last Name:</strong> <input type="text" size="17" maxlength="100" name="newsletter_lastname" />
    		</div>
    		</div>
    		<!-- End Name Forms -->
    	<!-- Start Contact Information Forms -->
    		<div style="padding: 10px;">
    			<div style="padding: 10px;">
    				<strong>Company Name:</strong> <input type="text" size="45" maxlength="150" name="newsletter_company" />
    			</div>
    			<div style="padding: 10px;">
    				<strong>Email:</strong> <input type="text" size="40" maxlength="100" name="newsletter_email" />
    			</div>
    			<div style="padding: 10px;">
    				<strong>Website:</strong> <input name="newsletter_website" type="text" value="http://www." size="40" maxlength="100" />
    			</div>
    			<!-- Begin Submit/Reset buttons -->
    				<input type="submit" name="button" value="Submit" /> &nbsp; <input type="reset" name="reset" value="Reset" />
    				<p>Please only press the submit button once, and only after you are sure all of your information is correct. It may take a few seconds to submit your data.</p>
    		</div>
    	<!-- End Submit/Reset buttons -->
    </form>
    Any help would be greatly appreciated

  2. #2
    uthus's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2006
    Location
    Ft Hood
    Posts
    75

    Re: CGI newsletter sign-up form

    Hi,

    A couple of questions:

    Is the script executable?

    Does it run as expected from the command line?

    When fixing a script I'll stick dummy data in for the variables. The script should run if there's no problem and spit out dummy output that I can go through to make sure the HTML is correct. If not, I'll go back through and tweak the problem.

    u

  3. #3
    BigAl75's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    2

    Re: CGI newsletter sign-up form

    Everything works fine now. The FTP program I was using was uploading the cgi file in binary instead of ACSII. Never used the program before, so I didn't know where to change it unil I did some looking around.

  4. #4
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: CGI newsletter sign-up form

    hmm yeah was gona say. Nothing wrong with your script nor your html form

  5. #5
    Anir's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2007
    Posts
    1

    Re: CGI newsletter sign-up form

    Hello
    I am queite new to this, but I have a question if you may help please,
    I have adesktop email marketing and an html form, how can I make the form of newsletter send subscriptions to my email then I will figure manualy it using the email marketing?
    Any help would be appreciated.
    Many thanks per advance
    Kind wishes
    Anir

  6. #6
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: CGI newsletter sign-up form

    Anir,
    There are a few ways you could go about doing this. The best method would be to use perl module Mail::Mailer (http://search.cpan.org/~markov/MailT...Mail/Mailer.pm).
    Code:
    $mailer = Mail::Mailer->new("sendmail");
    $mailer->open({ From => $your_email,
    To => $to_who_email,
    Subject => $subject,
    })
    or die "Can't open "send mail":  $!\n";
    print $mailer $your_message;
    $mailer->close();
    If you can't use the module Mail::Mailer, look for alternative modules that complete the same task OR use perls usual sendmail function.
    Last edited by vinyl-junkie; 10-22-2007 at 05:48 PM. Reason: Added code tags



Tags for this Thread